jquery select class inside parent div

后端 未结 3 1378
天命终不由人
天命终不由人 2020-12-15 05:13

I\'m trying to change the alt of the image, I\'m clicking by selecting the image\'s class (add_answer)

Note:

3条回答
  •  天涯浪人
    2020-12-15 05:45

    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).

提交回复
热议问题