javascript - Change div id on click -


i have few 'headlines' which, when clicked, them expand/change colour etc. shtere way of changing div on click of 1 of headlines whichever 1 click have it's properties changed. 1 problem need single instance...when click on 'headline' after clicking 1 previously, 1 clicked before hand need changed back.

so...if 'current' 1 have clicked:

<script> function clickedheadline() {    document.getelementbyid('current').style.width="auto"    document.getelementbyid('current').style.backgroundcolor="#999"   } </script> 

maybe can run script before 1 above tell div has id 'current', change , run above script...

i don't think i've explained hope can i'm trying do. saves me making function every time make headline along id's, it'll extremely confusing after while.

i agree case sensitive , think better add objet want modify :

 function clickedheadline(o) {    o.style.width="auto";    o.style.backgroundcolor="#999";    } 

and in html add

onclick="clickedheadline(this);" 

i think it's better, can reuse function :) .


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -