View Full Version : Change multiple div styles onclick
Silver89
Nov 1st 2008, 4:52 pm
Hi,
I'm trying to change multiple divs onclick with javscript,
Currently I can change one div no problem with:
<div class="navBack" onclick="this.className='catBack''">
However I want it to do the following:
<div class="navBack" onclick="this.className='catBack'&div.closeCross.style='display:none'">
Thanks
tarponkeith
Nov 1st 2008, 5:54 pm
onclick="this.className='catBack';div.closeCross.style='display:none';"
Maybe?
I'll test it right now...
Yeah, this worked in FF:
<html>
<head>
<style>
.className1 { background-color: #000; }
.className2 { background-color: #f0f; }
</style>
</head>
<body>
<div id="hi" onclick="this.className='className1';">a</div>
<div id="hi2" onclick="hi.className='className2';this.className='classname1';">b</div>
</body>
</html>
Silver89
Nov 1st 2008, 6:41 pm
The problem now is that it doesn't apply the display:none to divs within the div, can this be sorted easy?
tarponkeith
Nov 1st 2008, 7:23 pm
The problem now is that it doesn't apply the display:none to divs within the div, can this be sorted easy?
you could put the "display:none" in a class, like this:
<html>
<head>
<style>
.className1 { background-color: #000; }
.className2 { background-color: #f0f; }
.className3 { display: none; }
</style>
</head>
<body>
<div id="hi" onclick="this.className='className1';">a</div>
<div id="hi2" onclick="hi.className='className2';this.className='className3';">b</div>
</body>
</html>
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.