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';
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';
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;
if you are using jquery, then its a simple task.
suppose you have a button
then you can use jquery to assing its text by using
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script type="text/javascript">
var status="on";
$(document).ready(function(){
$("#myButton").text(val);
});
</script>
or you could pure javascript:
var status="on";
document.getElementById('myButton').innerHTML=status;
Guess this helps:
<button id="myButton" type="button" value=""></button>
<input id="myInputButton" type="button" value=""></button>
<script type="text/javascript">
var status = 'on';
document.getElementById('myButton').innerHTML = status;
document.getElementById('myInputButton').value = status;
</script>