Question

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

Was it helpful?

Solution

This is a pure guess, but would

var sc=element.closest('h3').next('.edit-mode:eq(0)'); alert(sc.get(0).id; });

do it for you?

OTHER TIPS

Have you tried something like:

$(".cs").live('click',function() 
{
    var element=$(this);
    var sc = element.parent().next('textarea.edit-mode'); 
    alert(sc.toSource());
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top