tags:

views:

38

answers:

2

Hi Guys.

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

+1  A: 

Have you tried something like:

$(".cs").live('click',function() 
{
    var element=$(this);
    var sc = element.parent().next('textarea.edit-mode'); 
    alert(sc.toSource());
}
Boycs
Omg I am so stupid ..Thanks Boycs!1
Alex
@Alex: you should accept answers that helped, so the users keep motivated to help you!
jigfox
+1  A: 

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?

Dan F