Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery append function giving syntax error in console.log

Tags:

jquery

$(".trade-button").append('<div>
<button tabindex="2" class="btn google-analytics-make-trade-click-trade-page"<span id="tradeTotal"></span>
</button></div>');

I'am trying to append html, but it's giving syntax error.

like image 521
Nadeem Avatar asked Jun 24 '26 17:06

Nadeem


1 Answers

The problem is that you wrote the appending string in multiple lines. You can't do it like this, this is not valid JavaScript. You can write it in one line, or escape it correctly.

$(".trade-button").append('<div><button tabindex="2" class="btn google-analytics-make-trade-click-trade-page">Trade For a Total of $0<span id="tradeTotal"></span></button></div>');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="trade-button"></div>

Or:

$(".trade-button").append('<div>' + 
                          '<button tabindex="2" class="btn google-analytics-make-trade-click-trade-page">' + 
                          'Trade For a Total of $0' + 
                          '<span id="tradeTotal"></span>' + 
                          '</button></div>');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="trade-button"></div>
like image 163
eisbehr Avatar answered Jun 26 '26 07:06

eisbehr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!