views:

50

answers:

1

Hi guys i previously asked a question and got a good solution. here is the question:

http://stackoverflow.com/questions/2536892/jquery-how-to-find-an-element-which-is-comming-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

+1  A: 

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

Nick Craver
Thanks for the solution, that really works perfectly!
ilkin