Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make button label dynamic using javascript?

What I want to do is be able to change the text inside of a button by making the text inside an actual variable.

Something like this:

<button type=button>status</button>

but instead of a string, it's a variable:

var status = 'on';
like image 930
Casa_De_Agua Avatar asked Dec 05 '12 06:12

Casa_De_Agua


1 Answers

If you're trying to assign the text of a button to a variable then it's as simple as following:

var buttonText = "click me!";      
document.getElementById("id-of-your-button").innerHTML = buttonText;
like image 57
trebuchet Avatar answered Oct 02 '22 12:10

trebuchet