taika chan
taika chan

Reputation: 43

javascript get variable value in <span> in Div

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

Upvotes: 0

Views: 1580

Answers (2)

Kakashi Hatake
Kakashi Hatake

Reputation: 3036

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>

Upvotes: 1

joe
joe

Reputation: 1489

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

Upvotes: 0

Related Questions