How can I channge this inline javascript to Unobtrusive JavaScript?
<input type="button" value="Text1" onclick="this.value=this.value=='Text1'?'Text2':'Text1';">
Thank you!
Thank you for your answears, but it doesn't work. My codes are:
php
<input id=\"button1\" type=\"button\" value=\"Text1\">
js file
document.getElementById('button1').onclick = function(){
this.value = this.value === 'Text1' ? 'Text2' : 'Text1';
}
or
document.getElementById('button1').addEventListener('click', function () {
this.value = (this.value === 'Text1') ? 'Text2': 'Text1';
}, false);
I tried everything you told me, but it didn't work! Neither with jquery.
Have I forgotten something?