In this study, using density functional theory and the SIESTA computational code, we investigate the electronic and optical properties of the armchair graphene nanoribbons and the armchair boron nitride nanoribbons of width 25 in the presence of a transverse external electric field. We have observed that in the absence of the electric field, these structures are semiconductors with a direct energy band at Γ point and applying electric field on them causes to change in the band structure, increasing the band gap and even eliminating the band gap. Increasing the intensity of the applying field on the graphene nanoribbons reduces the distance between the maximum of the highest valence band and the minimum of the lowest conduction band and shifts the convergence of these two bands in K space from the Γ point to the X point. The energy band gap of the boron nitride nanoribbons also has been decreased from 4.46 eV to less than 32.6 meV in presence of a transverse electric field of intensity about 0.30 V/Ang and a semiconductor-metal transition was observed in the presence of the stronger fields. Next, we investigate the effect of the transverse electric field on the optical properties of both nanoribbons. Of course, in order to study the optical behavior of these systems, we apply only a radiation with the parallel polarization. According to the changes that the electric field makes on the band structure, we observed changes in the location and intensity of the optical graphs peaks. Also with increasing the intensity of the field, we observe a significant increase in the static dielectric constant and the plasmonic behavior of these structures.