I see the method of getting second class name with jquery but how do I do it in mootools , my element is <li class="parent active">
I need to match full class name like li.parent.active and adjust height if that class is present I tried
$$('li').hasClass('parent active') or getProperty but all of them return true even if active is not present, if I add .parent.active I get
The expression is not a legal expression. now I must support mootols 1.1 ,1.2 ,1.3 working on CMS here so I started with the ugly one 1.1 version
this is how is actually needed
var holderdiv =$('mymenu');
if($$('li.parent.active')){holderdiv.setStyle({'height':'50px'});
if($$('li.parent.active') == true) returns true as in, it's truthy (defined, not null).
if you mean to say: is there at least one child element that has .parent and .active, you can do:
if (holderdiv.getElement("li.parent.active")) // at least one.
holderDiv.setStyle("height", 50); // setStyle uses a value pair, not an object.
if they are not children of holderdiv just do document.getElement or whateverElObj.getElement instead.
this will likely break in 1.11 due to old xpath stuff.
one way to do it so it works in all versions would be this (though you should only do this if MooTools.version is wrong due to performance cost of double loops):
var holderdiv = $("holderdiv");
if (holderdiv.getElements("li.parent").some(function(el){ return el.hasClass("active"); })) {
// at least one.
holderdiv.setStyle("height", 50);
}
the .some will run through all li.parent until it finds one that matches the condition (hasClass("active")) and then return boolean true else, false.
http://jsfiddle.net/dimitar/BqwAk/
if you need to keep a reference of the lis into a collection, use .filter instead:
var lis = holderdiv.getElements("li.parent").filter(function(el){
return el.hasClass("active");
});
if all have .parent and only one can be active, you don't really care so you can just do
if (holderdiv.getElement("li.active"))
or
if (holderdiv.getElement("li.active").hasClass("parent"))
... to double check if they don't all have .parent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With