"Syntax error malfunction: unexpected token <" when using jQuery append

Here is the jsFiddle demo of my problem.

This jquery snippet adds 3 divs after the click event is fired. However, the console says: "Syntax error malfunction: 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> 
+4
source share
2 answers

You have a line broken into several 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>"); 
+6
source

Try the following:

 $(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>"); 

The pluses at the end of the line are important, so just copy them and try.

+2
source

Source: https://habr.com/ru/post/1487776/


All Articles