Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Uncaught Syntax Error : Unexpected token < " when using jQuery's append [duplicate]

Tags:

jquery

append

Here is a jsFiddle demo of my problem.

This jquery snippet adds 3 divs once a click event is fired. However, the console says "Uncaught Syntax Error : Unexpected token < ".

script

$('#e16').on('click', function(){
 $(this).append("<div id='e17' class='kim2bb'>Alcohol 0.2+</div>
                 <div id='e18' class='kim2bb'>Alcohol 1.0~2.0</div>
                 <div id='e19' class='kim2bb'>Alcohol 0.05~1.0</div>");
});

html

<div id="e16" class="kim2bb">Drunken Drive</div>
like image 716
Deck Trout Avatar asked Feb 16 '23 03:02

Deck Trout


1 Answers

You have a string broken over multiple lines:

$(this).append("<div id='e17' class='kim2bb'>Alcohol 0.2+</div>" +
                "<div id='e18' class='kim2bb'>Alcohol 1.0~2.0</div>" +
                "<div id='e19' class='kim2bb'>Alcohol 0.05~1.0</div>");
like image 176
Igor Avatar answered Apr 25 '23 14:04

Igor