This code is not working. this+'>a'
isn't a valid syntax.
So, how can I add/remove a class in a child of this
? In this case an a
element.
jQuery(function ($) {
$("nav.menu>ul>li").hover(
function () {
$(this+'>a').addClass("hover_triangle");//error
},
function () {
$(this+'>a').removeClass("hover_triangle");//error
});
});
I can't do nav.menu>ul>li>a
because will select all a
elements in menu.
$('. rotation ul'). addClass('image_rotation'); The above code will add a class of image_rotation to every ul that is a descendant of any element with the class rotation .
You can simply document. querySelectorAll to select the list. use "firstElementChild" to get first child node and add class.
$(this).children('a').addClass('hover_triangle');
and with the full code:
jQuery(function($) {
$('nav.menu>ul>li').hover(function() {
$(this).children('a').addClass('hover_triangle');
},function() {
$(this).children('a').removeClass('hover_triangle');
});
});
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