views:

45

answers:

1

Hello everybody,

this is a snippet from my code:

$("#myid").append($("p:contains('text')").closest("div").clone());

I tried to get the first closest ancestor div-element of p containing 'text'.

I'm looking for an alternative to .closest() because I have to use jquery version 1.2.6. Do you have got an idea what I'm looking for?

I hope you can help me. I appreciate every hint, piece of code, etc..

+4  A: 

$('p').parents('div:first')

should do :)

Ionut Staicu
Just a question. If There were two p-elements containing the snippet of text I wouldn't get the second p-element, would I?
twistery
yeah, you can get second one using $('p:eq(1)').text();
Zain Shaikh
Like $("#myid").append($("p:contains('text'):eq").parents('div:first').clone());? I'm sorry I understand what you mean, but got some problems with the syntax.
twistery
Okay, I tried some things and got what I wanted. $('p').parent('div') does it.
twistery