Wednesday, August 22, 2012

Stating a universal ID in Javascript function

I have the following function for changing the CSS display on a given DIV



function(){

if(document.getElementById(\'kitstory\').style.display === \"none\")
{
document.getElementById(\'kitstory\').style.display = \"block\";
} else{
document.getElementById(\'kitstory\').style.display = \"none\";
}
}


I\’m using onclick in a link to call the function as and when required.


This works fine on my DIV with the ID \”kitstory\”, but is there a way I can use this function for more than one DIV (I\’ll have several articles on 1 page with different DIV\’s I want the function to effect)? I\’ve tried leaving the id blank but it doesn\’t run.






Rating: 2 out of 5 based on 6 ratings



The post Stating a universal ID in Javascript function appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/stating-a-universal-id-in-javascript-function.html

No comments:

Post a Comment