javascript - Change button colour -


my idea show image on map press button. change colour of button after has been clicked , should stay colour until deselect button. colour of button should change original colour.

here code button:

<button type="button" class="button" id="tram7" class="deselected"> tramlinie 7 </button> 

and here function inserts image map:

$('#tram7')[0].onclick = function() {     if (overlaytram7.getmap() == map) {         $('#tram7').addclass('deselected');         overlaytram7.setmap(null);     } else {         $('#tram7').removeclass('deselected');          overlaytram7.setmap(map);     } }; 

the style change worked hover, don't know how change style of clicked button.

.button {  font-family: calibri, sans-serif;  font-size:13px;  font-weight: bold;   width: 160px;  height: 25px;  background:grey;  color: white }  .button:hover {  color: white;  background:green } 

thanks in advance.

your question isn't clear me. wanting change color while user clicking on button? if so, that's pretty easy, css:

you'll want psuedo-selector, :active

.button:active {    color: white;    background:green } 

here example


update: clarified want button's color changed after being clicked. acting toggle. luckily jquery has simple solution you: toggleclass()

updated example using toggleclass()


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -