0

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>';
3
  • what is the error and what you want to achieve? Commented Mar 4, 2020 at 5:57
  • i think this answer would help you !!! stackoverflow.com/a/6631748/10967697 Commented Mar 4, 2020 at 6:01
  • Please note it is invalid to have interactive content (e.g. a button) inside a link : developer.mozilla.org/en-US/docs/Web/HTML/Element/a . You are better off styling the link to something that resembles a button. Commented Mar 4, 2020 at 6:28

2 Answers 2

4

Remove the quote on '/' => '/

pop_str = pop_str + '<a href="'+ brand1 + 'vs' + brand2 + '"/><button class="btn master_btn">Compare Now!<button></a>';
Sign up to request clarification or add additional context in comments.

4 Comments

actually it shows whole <button></button> tag in link?
yes of course .They will parse the string and variable
not but that's not a solution that I want! on the button I want the link
for your question I write this javascript but it's showing error. can anyone solve this how to write it correctly? its not showing any other scenario .please update the correct question
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}

2 Comments

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.
no, when I click on button then there is no link in your solution!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.