I can't make it work, btn is a string here but 'licz' is a variable, I've tried anything, could someone help me and tell what is wrong with that ? Licz is a counter from 1 to 100, i want that line to give something like
btn1, btn2 etc
$('#slider').append("<div id='btn ' + \\'licz><i class='fa fa-circle fa-2x' aria-hidden='true'></i></div>");
Can someone show me the proper way to do this ? I would be gratefull
$('#slider').append("<div id='btn" + licz + "'><i class='fa fa-circle fa-2x' aria-hidden='true'></i></div>");
You would need to append it to your string like so:
$('#slider').append("<div id='btn" + licz + "'><i class='fa fa-circle fa-2x' aria-hidden='true'></i></div>");
Or if you are using ES6
$('#slider').append(`<div id='btn${licz}'><i class='fa fa-circle fa-2x' aria-hidden='true'></i></div>`);
Your variable is not appended correctly it needs to be like this:
$('#test').append("<div id='btn '>" + licz + " <i class='fa fa-circle fa-2x' aria-hidden='true'></i></div>");
HERE is an example of it working
You need to stop and start the string appropriately where you want to. So you might instead like to try
$('#slider').append("<div id='btn " + licz + "><i class='fa fa-circle fa-2x' aria-hidden='true'></i></div>");
Breaking the string properly with double quotes to allow you to insert the variable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.