开发者

JavaScript and error "end tag for element which is not open"

I have problem with validation such code

funct开发者_JAVA技巧ion show_help_tip(event, element) {

  var $e = $(element);

  var pos = $e.offset();

  $('.body-balloon',$help_tip_div).html($(' <p>&nbsp;</p> ').html(element.getAttribute('title')));

  $help_tip_div.css({position:'absolute',top:530,left:pos.left+$e.width()-20}).show();

}

end tag for element "P" which is not open

What's wrong?


You need to escape the / to stop it terminating the script element.

"<\/p>"

The validator should link (via a couple of steps) to http://www.htmlhelp.com/tools/validator/problems.html#script

This is an oddity of SGML, in which an element defined as containing CDATA (such as a script element) will be terminated by any end tag, but if that end tag doesn't match the start tag, then it is invalid.

In a JavaScript string, "/" and "\/" are equivalent, but in HTML </p> and <\/p> are not, so this lets you avoid having something that appears (to the HTML parser) to be an end tag in your script.


<p> does not need an end tag. You can use <p>, and I think you can use <p/> if you are OCD or using XHTML, but that mark does not have any content so no end tag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜