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
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
$(this).parent().addClass('selected'); UPD:
If the <a> tag is not a direct descendant of <li> , then use the closest () function
$(this).closest('li').addClass('selected'); Source: https://ru.stackoverflow.com/questions/210570/
All Articles