function swapClass() {
// assumes all elements with class='nav_p'are <p>
var aP=document.getElementsByTagName('p');
for(var i=0; i<aP.length; i++) {
if(aP[i].className==='nav_p') {
aP[i].className='nav_p_small';
}
}
}
At least 98% of internet users' DNA is identical to that of chimpanzees
Well, that works for <p> but what if i want to change the class of a DIV? I tried to do it by myself but i'm not familiar with javascript, so.. can u guys give me a light?
function swapClass() {
// assumes all elements with class='nav_div'are <div>
var aDiv=document.getElementsByTagName('div');
for(var i=0; i<aDiv.length; i++) {
if(aDiv[i].className==='nav_div') {
aDiv[i].className='nav_div_small';
}
}
}
Last edited by deepode; 11-05-2012 at 10:23 AM.
Reason: to change [PHP] with [CODE]
function swapClass() {
// assumes all elements with class='nav_div'are <div>
var aDiv=document.getElementsByTagName('div');
for(var i=0; i<aDiv.length; i++) {
if(aDiv[i].className==='nav_div') {
aDiv[i].className='nav_div_small';
}
}
}
Thanks! This pretty much worked. But i noticed that when i change the class by clicking the div i cant click again to just swap to original class. How can i apply this swap between classes?
Code:
function changeClass(x)
{
x.className=(x.className=="boxes")?"boxes-min":(x.className=="boxes-min")?"boxes":"boxes-min";
}
Bookmarks