i’ve looked around on stackoverflow but only found a way to do the thing i want with jQuery. The code i found is this:
$("li:has(ul)").each(function(){
$(this).find(">a").addClass("hasSubmenu");
});
Now I would like to turn that into plain Javascript. So I don’t need to include the jQuery librarie for this short piece of code.
Can somebody help me with turning this into JS code?
There are two answers here that I see. In modern browsers, you can use the
querySelectorandquerySelectorAllmethods to perform queries similar to jQuery:If you have to support IE, you could go with a bit more code:
Here’s a jsFiddle with both: http://jsfiddle.net/ppxcy/1/