开发者

using closest().find().text()

开发者 https://www.devze.com 2022-12-25 13:03 出处:网络
Hi guys i previously asked a question and got a good solution. here is the开发者_C百科 question:

Hi guys i previously asked a question and got a good solution. here is the开发者_C百科 question:

jquery: how to find an element which is coming 2 elements before current element

when im using the solution which i got :

paragrafheading.push($(this).closest('> h3').find('> h3').text());

im getting only [object Object] instead of the element text


You're getting that because it's not finding your <h3> correctly, so there's nothing to call .text() on, so you're pushing an empty set of jQuery elements. I would use this to find the <h3> instead:

$(this).closest('p').prev('h3').text();

Not sure what the previous answer was after, but this is a bit cleaner and, more importantly, works :)

0

精彩评论

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

关注公众号