I would like to create a tab view for my php application using Mootools. I have n
number of tabs created from php script. My view is as follows.
<div>
<ul id="1">
<li>Popular</li>
<li>New Addition</li>
</ul>
</div>
<div>
<ul id="2">
<li>Popular</li>
<li>New Addition</li>
</ul>
</div>
...
<div>
<ul id="n">
<li>Popular</li>
<li>New Addition</li>
</ul>
</div>
How can apply style class active
according to the clicks on Populalar
or New Addition
under each tabs.
Thanks
I would like to create a tab view for my php application using Mootools. I have n
number of tabs created from php script. My view is as follows.
<div>
<ul id="1">
<li>Popular</li>
<li>New Addition</li>
</ul>
</div>
<div>
<ul id="2">
<li>Popular</li>
<li>New Addition</li>
</ul>
</div>
...
<div>
<ul id="n">
<li>Popular</li>
<li>New Addition</li>
</ul>
</div>
How can apply style class active
according to the clicks on Populalar
or New Addition
under each tabs.
Thanks
Share Improve this question edited Jan 20, 2011 at 8:13 Sean Patrick Floyd 300k72 gold badges476 silver badges595 bronze badges asked Jan 20, 2011 at 7:52 AadiAadi 7,10928 gold badges102 silver badges148 bronze badges3 Answers
Reset to default 5var tabs = document.getElements('li');
tabs.addEvent('click', function() {
tabs.removeClass('active');
this.addClass('active');
});
Try an example.
Here's how to do it in MooTools:
var activeElement = null;
$$('div ul li'
/* you probably want a better selector,
how about giving a parent element an id? */
).each(function(item){
item.addEvent('click',function(event){
$(event.target).addClass('active');
if(activeElement != event.target){
if(activeElement!=null)
$(activeElement).removeClass('active');
activeElement = event.target;
}
});
});
Update: Here's an improved version, thanks @steweb, source:
$$('#containerID li').each(function(item){
item.addEvent('click',function(event){
// minor improvement to steweb's code,
// restrict to .active inside container
$$('#containerID .active').removeClass('active');
this.addClass('active');
});
});
It requires the root div to have the id "containerId":
<div id="containerId">
<ul id="1">
<!-- etc -->
object.className = 'active';
( Where object is what you want to highlight )