Sahil shaikh
Sahil shaikh

Reputation: 69

how to add multiple javascript variable in html a href tag

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>';

Upvotes: 0

Views: 531

Answers (2)

prasanth
prasanth

Reputation: 22490

Remove the quote on '/' => '/

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

Upvotes: 4

Simeon Ikudabo
Simeon Ikudabo

Reputation: 2190

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}

Upvotes: 2

Related Questions