Jquery Select Class Inside Parent Div
I'm trying to change the alt of the image, I'm clicking by selecting the image's class (add_answer) Note: .add_answer shows up multiple times inside different containing div's jQu
Solution 1:
you can use the parent div as the scope:
$('.add_answer',$(this).parent('div:first')).attr('alt',count);
Solution 2:
This should work:
$(this).parent("div").find(".add_answer").attr("alt", count);
Solution 3:
You code is almost correct. Required change is to use .find instead of .$ after .parents method. Use of .parent instead of .parents should be avoided, this way your code will be more unobtrusive (precisely - this way img can be non-direct child of the div).
$(this).parents('div:eq(0)').find('.add_answer')
You can manipulate :eq(0) to select eg third parent div using :eq(2).
Post a Comment for "Jquery Select Class Inside Parent Div"