开发者

This is ugly and there has to be a better way to write it in jQuery

开发者 https://www.devze.com 2023-01-28 20:47 出处:网络
$(this).parent().parent().parent().parent().find(\'[name=reply_to_id]\'); Thats just stupid looking, but its the best way i can think of writing it. I tried parentsUntil(\'li\') but that didnt work
$(this).parent().parent().parent().parent().find('[name=reply_to_id]');

Thats just stupid looking, but its the best way i can think of writing it. I tried parentsUntil('li') but that didnt work at all and i also tried parents('li') and closest('li'). Isnt there something in jQuery with the equivalent of:

$(this).firstParentThatMatchesThis('li').find('[name=reply_to_id]');

If not i开发者_JAVA百科 think ill try submitting it to the jQuery core...

Here is my HTML (long so i put it on pastebin): http://pastebin.com/FypJ9WGe

Working on getting JSFiddle in there...


Try this:

$(this).parents("li").eq(0).find('[name=reply_to_id]');

Example: http://jsfiddle.net/FvzT9/

But, closest should work as well:

$(this).closest("li").find('[name=reply_to_id]');

Example: http://jsfiddle.net/FvzT9/1/


$(this).closest('li').find('[name=reply_to_id]');
0

精彩评论

暂无评论...
验证码 换一张
取 消