Home Changing button created with <button> text with JavaScript
Reply: 2

Changing button created with <button> text with JavaScript

Tino Terävä
Tino Terävä Published in 2018-02-14 09:09:18Z

My code looks like this

in .html

<button type="button" onclick="toggle()" id="toggleButton">more ⇓</button>


function toggle(){
document.getElementById("toggleButton").innnerHTML="less ⇑";}

The button appears in my page with the more text, but clicking the button does not do anything.

In I do have reference

<script src="button.js"></script>

And the name of my javescript file is button.js

Mamun Reply to 2018-02-14 09:11:19Z

It should be innerHTML not innnerHTML

document.getElementById("toggleButton").innerHTML="less ⇑";
<button type="button" onclick="toggle()" id="toggleButton">more ⇓</button>

Kishor Velayutham
Kishor Velayutham Reply to 2018-02-14 09:15:55Z

Try this ..

<input onclick="toggle()" type="button" value="more ⇓" id=myButton1"></input>


    function toggle()
        if (this.value=="more ⇓") 
             {this.value = "less ⇑";}
             {this.value = "more ⇓";}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.3024 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO