innerText does not accept white space

Asked

Viewed 182 times

1

For some reason, when I use white space, passing something to the 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 as content 'Bom_dia' appears normal, but if you have '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.

  • Can you review the value being assigned to innerText? It looks like a tag strange </text> that doesn’t make much sense.

  • Hi, it’s inside a text tag, it needs to be, the full statement looks like this: $texto_dia="<text class="font_botao_carmesim" onclick=window.parent.Document.getElementById('frame_calendario_variable'). src='calendario_variables.php? dia=$cont'; onmousemove=window.parent.Document.getElementById('calendario_obs'). innerText='$rodape'>$cont</text>"; only the end of the problem, if the footer variable has space does not appear, if it does not work perfectly.

  • From what it seems you are only forgetting the quotation marks in onmousemove, in html the quotation marks are only not mandatory if there is no space, so your code would go up to "good", creating an incomplete string 'bom and ignore the rest, giving variable bom undefined

1 answer

2


Always use quotes for attribute values HTML does not require you to use quotes, but I recommend that you always use to avoid this kind of problem.

Cause of the problem:

When you do not use quotation marks, the result of your code is: Assuming "good morning" as variable value $rodapé

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

The browsers will put the quotes getting:

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

cutting the dia' and ignoring him;

or

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

cutting the dia, by removing the simple quotes from the end and placing it as a new attribute in the tag with no value.

How does JS disregard these simple "orphan" quotes (as in 'bom), he tries to search bom as being a variable, soon will give that the variable is undefined (you can check in the console, possibly will be there).

How to correct:

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

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

When I can not use quotes?

When your attribute contains NO space, because the separation of attributes in the tag is done by it.

  • Perfectly, thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.