Suppose:

$('li a').click(function(){ $(this).addClass('selected'); }); 

And how to make so that selected would be added not to <a> but to <li> ??? That is, I need to perform operations on the element that is above this

    1 answer 1

     $(this).parent().addClass('selected'); 

    parent ()

    UPD:

    If the <a> tag is not a direct descendant of <li> , then use the closest () function

     $(this).closest('li').addClass('selected'); 
    • And in parentheses parent () you can specify an element? - igolka97
    • According to the documentation for the link, you can specify an expression for filtering, but this is if you used parent () for the element set. - Gil
    • If your <a> tag is not a direct descendant of <li>, then use the closest () function $ (this) .closest ('li'). AddClass ('selected'); - Gil