Solution 1 :

Remove the quote on '/' => '/

pop_str = pop_str + '<a href="'+ brand1 + 'vs' + brand2 + '"/><button class="btn master_btn">Compare Now!<button></a>';

Solution 2 :

To simplify this you could use the back tick character `:

pop_str =  `${pop_str}<a href="${brand1}vs${brand2}"><button class="btn master_btn">Compare Now!<button></a>`

You simply place your variables within ${variable}

Problem :

I write this javascript but it’s showing error. can anyone solve this how to write it correctly?

actually I want to show button and on the button, I want link

pop_str = pop_str + '<a href="'+ brand1 + 'vs' + brand2 + '/'><button class="btn master_btn">Compare Now!<button></a>';

Comments

Comment posted by Manjuboyz

what is the error and what you want to achieve?

Comment posted by stackoverflow.com/a/6631748/10967697

i think this answer would help you !!!

Comment posted by developer.mozilla.org/en-US/docs/Web/HTML/Element/a

Please note it is invalid to have interactive content (e.g. a

Comment posted by Sahil shaikh

actually it shows whole tag in link?

Comment posted by prasanth

yes of course .They will parse the string and variable

Comment posted by Sahil shaikh

not but that’s not a solution that I want! on the button I want the link

Comment posted by prasanth

for your question

Comment posted by Simeon Ikudabo

Right after a posted this someone showed a similar answer lol. But they’re correct, using the back tick can be more efficient in this situation.

Comment posted by Sahil shaikh

no, when I click on button then there is no link in your solution!

By