JQuery text and variable inside .html ()

it is probably very simple, but I can’t understand :)

 $('#myDiv').html('<a onclick="remove_item(variantId);">Remove</a>');

variantId is a JS variable, so I need to pass it to the code above.

+3
source share
3 answers
 $('#myDiv').html('<a onclick="remove_item(' + variantId + ');">Remove</a>');
+4
source

use it that way -

 $('#myDiv').html('<a onclick="remove_item('+variantId+');">Remove</a>');
0
source
$('#myDiv').html('<a onclick="remove_item('+variantId+');">Remove</a>');
0
source

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


All Articles