Why am I getting this JS error?

This is mistake:

Uncaught SyntaxError: Unexpected token ILLEGAL
d.d.extend.globalEvaljquery-1.5.1.min.js:16
d.ajaxSetup.converters.text scriptjquery-1.5.1.min.js:16
bQjquery-1.5.1.min.js:16
vjquery-1.5.1.min.js:16
d.support.ajax.d.ajaxTransport.send.c

Here is jQuery:

$("div#notif_js").html(' ');

$("div#notification_box").html('<div class="notification">
  <p><img alt="Justin meltzer" class="feed_image_notif" src="/system/photos/46/tiny/Justin Meltzer.jpeg?1303109121" /> JMeltz 
   added a comment to <b>second</b> by <img alt="Justin meltzer" class="feed_image_notif" src="/system/photos/45/tiny/Justin Meltzer.jpeg?1303109101" /> Justin Meltzer</p>
  <a href="/videos/506"></a>
</div>
<div class="notification">
  <p><img alt="Justin meltzer" class="feed_image_notif" src="/system/photos/46/tiny/Justin Meltzer.jpeg?1303109121" /> JMeltz 
   added a comment to <b>second</b> by <img alt="Justin meltzer" class="feed_image_notif" src="/system/photos/45/tiny/Justin Meltzer.jpeg?1303109101" /> Justin Meltzer</p>
  <a href="/videos/506"></a>
</div>
<div class="notification">
  <p><img alt="Justin meltzer" class="feed_image_notif" src="/system/photos/46/tiny/Justin Meltzer.jpeg?1303109121" /> JMeltz 
   added a comment to <b>second</b> by <img alt="Justin meltzer" class="feed_image_notif" src="/system/photos/45/tiny/Justin Meltzer.jpeg?1303109101" /> Justin Meltzer</p>
  <a href="/videos/506"></a>
</div>
<div class="notification">
  <p><img alt="Justin meltzer" class="feed_image_notif" src="/system/photos/46/tiny/Justin Meltzer.jpeg?1303109121" /> JMeltz upvoted bhbu </p>
   <a href="/videos/505"></a>  
</div>      
<div class="notification">
  <p class= "all_notifications">All Notifications</p>
  <a href="/videos/notification_go"></a>
</div>');
+3
source share
2 answers

Javascript does not allow you to have multiple lines inside your lines. You either need to convert each line to \ n, for example:

$("div#notification_box").html('line1\nline2');

or precedes the end of each line as follows: \

$("div#notification_box").html('line1\
line2');

The first method seems to be more widely used, although the second method looks better in my opinion.

In addition, a good and easy way to check javascript errors is to run it through a javascript delimiter, for example http://www.javascriptlint.com/online_lint.php or http://www.jslint.com/ (although jslint does not report an error like this as good as javascriptline).


+1
source

jQuery 1.5.2 +

http://jsfiddle.net/XSAb2/

EDIT: , , StackOverflow,

0

All Articles