0

I want to put variable value here, but I don't know the syntax error. How can I use the '' "" .. to put the variable in the below sample ( in ) ?

Leave.innerHTML =  '<div class="popup" onclick="myFunction()"> 
 <span class="popuptext" id="myPopup"> ******Variable Put here****** </span></div>' ;
   }
1
  • '<div>' + yourVariable + '</div>' or template literal Commented Mar 24, 2017 at 8:59

2 Answers 2

1

Try this:

Exit your string from this point and join the value you want to use and rejoin the initial string.

'<div class="popup" onclick="myFunction()"> <span class="popuptext" id="myPopup">'+variable+'</span></div>';

var Leave = document.getElementById("leave");
var variable = "Your variable value goes here";
Leave.innerHTML =  '<div class="popup" onclick="myFunction()"> <span class="popuptext" id="myPopup">'+variable+'</span>   </div>';

console.log(Leave.innerHTML);
<div id="leave">initial code...</div>

Sign up to request clarification or add additional context in comments.

Comments

0

this should be enough.
var str = '<div class="popup" onclick="myFunction()"> <span class="popuptext" id="myPopup">' + theVarYouWant + '</span> </div>' Leave.innerHTML = str;

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.