jQuery next (ish) selector
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); 开发者_StackOverflow中文版
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
Have you tried something like:
$(".cs").live('click',function()
{
var element=$(this);
var sc = element.parent().next('textarea.edit-mode');
alert(sc.toSource());
}
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?
精彩评论