Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery next (ish) selector

Tags:

jquery

I've been banging my head against a wall with this code all morning and finaly decided to come here for some help.

I have the following markup.

<h3 class="element-title">Summary <span class="cs">THIS IS AN IMAGE</span></h3>

<textarea class="edit-mode" id="summary-<?php echo($randomId); ?>"><?php echo(br2nl($erow['summary'])); ?></textarea>

And the folliwing Jquery.

$(".cs").live('click',function() {
var element=$(this);       

var sc=element.prev(1).next('.edit-mode'); alert(sc.toSource()); });

What I am trying to do is when the is clicked for it to return the ID or even the object of the textarea below it. Unfortunately the page is very dynamic so I have to select on the classname of ".edit-mode" so referencing on ID is not an option - If it was I would be doing it.

THe problem I think lyes in that the span is inside the <h3> tag so I have to go out of it and then next() but doing that doesnt work.

Can anyone help?

Thanks in advance

Alex

like image 879
Alex Avatar asked Aug 05 '26 02:08

Alex


1 Answers

Have you tried something like:

$(".cs").live('click',function() 
{
    var element=$(this);
    var sc = element.parent().next('textarea.edit-mode'); 
    alert(sc.toSource());
}
like image 67
Boycs Avatar answered Aug 08 '26 21:08

Boycs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!