+ 8
How can I change color when I click on button by using javascript?
html or js
7 odpowiedzi
+ 7
HTML
<button onclick=color()></button>
JS
function color(){
document.getElementmById("id of your element").style.color = "your color code"
};
If you don't understand, please tell me, i will explain.
+ 9
very thank for all answers
+ 2
Simplest way is to do this online, but maybe you should use a function handle this.
https://code.sololearn.com/W8s2OwM8xBJg/?ref=app
+ 2
<button onclick="this.color='red'" >Change color</button>
// this change button color to red when click.
+ 2
Ok, thanks
+ 1
Dennis Hain Do one have to write "javascript:" in onclick attribute? I use it without and it works.
+ 1
I think there is no need to use this prefix any longer, but in the good old days it'd made sense.