innerText does not accept white space

1

For some reason, when I use white space, passing something to innerText nothing happens. If I pass 'Bom_dia' everything appears normally, but if I pass 'Good morning' it shows nothing.

onmousemove = window.parent.document.getElementById('calendario_obs').innerText=
'$rodape'>$cont</text>

If the variable $rodape has 'Good_day' content appears normal, but if there is 'Good morning' nothing happens. If I take the variable and put it directly the value happens the same error then it should have nothing to do with the variable in PHP. Thanks in advance.

    
asked by anonymous 09.03.2017 / 16:29

1 answer

1

Always use quotation marks for attribute values HTML does not force you to use quotation marks, but I recommend that you always use it to avoid such problems.

Problem Cause:

By not using quotation marks, the result of your code is: Assuming "good day" as value of variable $rodapé

onmousemove=window.parent.document.getElementById('calendario_obs').innerText='bom dia>$cont</text>

Browsers will match the quotes:

onmousemove="window.parent.document.getElementById('calendario_obs').innerText='bom">$cont</text>

by cutting dia' and ignoring it;

or

onmousemove="window.parent.document.getElementById('calendario_obs').innerText='bom" dia>$cont</text>

By cutting dia , removing the single quotation marks from the end and putting it as a new attribute in the idle tag.

As JS disregards this "orphan" single quotation mark (as it is in 'bom ), it tries to look for bom as being a variable, then it will give the variable undefined (you can check it on the console, possibly it will be there) .

How to fix:

Just add the quotation marks around the entire JS code. Your code should then be:

onmousemove = "window.parent.document.getElementById('calendario_obs').innerText='$rodape'">$cont</text>

When can I not use quotation marks?

When your attribute does not contain ANY space, the attribute's separation in the tag is made by it.

    
09.03.2017 / 17:19