views:

45

answers:

1

Hi,

<label><input type="checkbox" id="Exep1" checked="checked" onclick="Do(this);"/> My label text here</label>

I used :

function Do(T){
var XcEP = $(T).parents().html().match(/^[-\s]*(.+?)[\s()\d]*$/,"i")[1]);
alert(XcEP);
}

The function above alerts:

<input type="checkbox" id="Exep1" checked="checked" onclick="Do(this);"/> My label text here

But i want only "My label text here" to be in alert!

Any help is too much appreciated

Thanks

+1  A: 
$(T).closest('label').text();

?

strager
Unfortunately i got this:$(T).closest is not a function
Mbarry
@unknown (yahoo), Upgrade to jQuery 1.3.
strager
or just use `parents` instead of `closest`. But yeah, you don't want to be using older jQueries if you can help it.
bobince
Thank you bobince! This is good:$(T).parents('LABEL').text().match(/^[-\s]*(.+?)[\s()\d]*$/,"i")[1];About jquery version yes i'll update it!
Mbarry