innerHTML not inserting the full value

i was making a password generator with html,css,js and everything is fine. the password is being displayed on the screen correctly but sometimes full password isnt being inserted in the innerHTML . i tried console logging the value of password just before inserting in innerHTML and it is showing full password but while inserting only some characters are inserted .
for example if my password variable contains a string “al;khpa8gjna[8nnapougf”, then only “al;khpa” is being inserted in the HTML . sometimes its working pretty fine and sometimes it is showing this error.

script → javascript/js/passGenerator/script.js at af01588dd69e427dfce71a4043c9142028c92ac3 · vishumonk-ey/javascript · GitHub

Hello,
this behavior of innerHTML property could be because the browser or some sort of security mechanism in it identified the text you are trying to add to DOM as a potential security threat although clearly it is not.
It is recommended to use innerText or textContent properties when trying to add text to a specific element, normally they will not cause that unexpected behavior

You need to replace the special characters with character references.

MDN: Character references: including special characters in HTML.

Or, as suggested, just use a text only property.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.