May 22, 201412 yr Please advise mei am starteri want to creat button with alternate color i want button with default color when i click the button change the color and process my work and then re-click the button return to default color how i can do it by whatever css or javascript?
May 22, 201412 yr you can use the JS onClick event for the button however with the two separate changes may be a little it more advanced than a starter. This may be of use to you http://www.w3schools.com/jsref/event_onclick.asp There are also ways to do this using the jQuery library but again may be a little bit more advanced
May 23, 201412 yr Author please can u create sample at jsfiddle.net i do not understand the what mean it was at http://www.w3schools...ent_onclick.asp
May 23, 201412 yr @@koolingblade Hiii, I think if you want to Click on color therfore you should use Java Script. if you want to cursor hover color than you should use hover attribute in css, Find Bellow Code... Html code : <button id="ButtonId">Hello</button> CSS code .ButtonClicked { background-color:Red; } Java Script $('#ButtonId').on('click',function(){ $(this).toggleClass('ButtonClicked'); }); Edited May 23, 201412 yr by Marlenmorlock
May 28, 201412 yr I wouldn't use JavaScript to toggle a class. Try something like this HTML: <button class="mybutton">Button text</button> CSS: .mybutton:active { background-colour: #ff0000; } :active is the pseudo state on an element when it is being clicked.
Create an account or sign in to comment