开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜