tags:

views:

19

answers:

1

Hi all, I was using JSLint to validate my code and i received the following error:

"expecting <\/ instead of <\"

I got that for my HTML code and JavaScript code. For example:

element.innerHTML += "<p>here's what happened: You are <b>" + aVariable + " </b> years old.</p>";

and:

<input type="text" name="enterText" id="nameOfPerson" onblur="submitValues(this)" size="50"  value="Enter your name"/>

Can anyone tell me why this is happening?

A: 

In the JSLint section on HTML, it says:

JSLint also checks for the occurrence of '</' in string literals. You should always write '<\/' instead. The extra backslash is ignored by the JavaScript compiler but not by the HTML parser. Tricks like this should not be necessary, and yet they are.

PanCrit
hmm i see. Is the extra backslash part and parcel of valid HTML code?
HTMLCSS_noob
I think what's going on is multiple levels of escape characters. When JSLint mentions the HTML parser, it's not the parser that will eventually interpret the </, it's the parser that is looking at "...<\/...". I think the point is to not confuse that parser into thinking that you've descended a level of HTML structure even though you were inside a quoted string at the time. But that's a guess. I only really know that Doug Crockford knows what he's talking about (and has talked to all the experts). You should believe what JSLint says.
PanCrit