What is the JavaScript version of sleep()? So it would replace the 'sports shops' with 'Food shops' when I click on the "Food Shops" button. While using W3Schools, you agree to have read and accepted our. Basically, you could add an onclick event to the button referencing to a function:
Hello
Step 2) Add JavaScript: Example function myFunction () { var x = … After seeing Toggling button text in jquery this question, I tried to re create it in my situation but can't seem to have it work. Use the setTimeout () method to change the text back after a delay. Use the background-color property to change the background color of Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. The onclick attribute is part of the Event Attributes, and can be used on any HTML elements. Examples might be simplified to improve reading and learning. By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy. Find centralized, trusted content and collaborate around the technologies you use most. (\renewcommand doesn't work ), Manhwa about a girl who got eaten by a snake protecting her sister. If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail: .button1 {background-color: #4CAF50;} /* Green */, W3Schools is optimized for learning and training. How to Add an Onclick Effect with HTML and CSS Solutions with HTML and CSS The most common way of creating a click event with CSS is using the checkbox hack. When the button gets clicked, update the state variable. How do I check if an element is hidden in jQuery? Ah yes right you are - I have corrected it - just a typo! Execute a JavaScript when a button is clicked: Try it Yourself » P Example Click on a

element to change its text color to red:

, ,