& nbsp without semicolon

I am using prototype.js in a web application. I populate some Divs dynamically by selecting some radio buttons. Before filling the content in the Div, I clear the previous content using the prototype update method as -

$('item').update('');

      

In IE this breaks the line automatically, but not in Firefox 3.5. So, to work the same way as IE, I changed the code as -

$('item').update('&nbsp');

      

This has now worked for me as expected. But generally "& nbsp" is used with a semicolon ($ nbsp;) . I want to know if this code might fail. For example, are there any chances where & nbsp will appear instead of a space? But some browsers may be smart enough to detect a coding error by a programmer and auto-correct it.

+2


source to share


4 answers


The trailing semicolon can be omitted, but is not recommended at all. See this note in the HTML 4 spec regarding symbolic links :



In SGML, the final ";" after a symbolic link in some cases (for example, on a line break or immediately before a tag). In other circumstances, it cannot be eliminated (for example, in the middle of a word). We strongly recommend using ";" in all cases, to avoid problems with user agents that require this symbol to be present.

+10


source


NEVER rely on browser auto-correct or "recommended" behavior.



If your code is wrong, then (a) it is wrong and (b) browsers might do incompatible things with it.

+7


source


I agree, tricky markup and JavaScript errors are a disaster for debugging any problems you have in the future, as you cannot eliminate the tricky markup by causing the browser to misinterpret the code.

0


source


not sure if this will help (or change anything), but the correct syntax won't actually have single quotes:

$('element').update();

      

0


source







All Articles