1

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

4 Answers 4

2
    $('#slider').append("<div id='btn" + licz + "'><i class='fa fa-circle fa-2x' aria-hidden='true'></i></div>");
Sign up to request clarification or add additional context in comments.

Comments

1

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>`);

Comments

1

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.