I use this logic to get the next input, and to search for the next
input if there were intervening elements, for example:
divinput/div
div
table
trtd//tdtd/td/tr
trtd/tdtdinput/td/tr
/table
/div
The function will iterate through until it finds the next input, even
if it is not the next element:
function tabOver(ele) {
var possInput = $(ele).parent().next().children('input');
//var nextInput = (possInput.size()0) ? possInput.focus() : $
(ele).parent().parent().next().find('input').focus();
Unfortunately for me, for some reason this focused on the last input
in the table, not the next, in both ie6 and ie7. I haven't gotten
around to filing a bug report yet or to even see if I'm making
incorrect assumptions...but I did find a work-around by using attr()
and the regular getElementByID:
var nextInput = (possInput.size()0) ? possInput.attr('id') : $
(ele).parent().parent().next().find('input').attr('id')
var moveTo = document.getElementById(nextInput);
moveTo.focus();
}
Bearing in mind that each element you're searching for would need an
id (or a class, if you used .attr(class)). I'm hoping the first one
works for you because I think the second one is cheating, like running
out of bounds, behind the bench and back on the field to catch the
touchdown pass.
I'm sure you can modify to fit your needs.
Eric
On Jul 9, 8:22 pm, jmbJq [EMAIL PROTECTED] wrote:
Been using jQuery for a while, but can't seem to figure this one out.
What I want to do is get the next span element when someone clicks on
the text inside the first span element. Then when someone clicks on
the text in the second span element, get the next span, and so on. If
someone clicks on the last span, it should not select any further span
elements (i.e. it should not wrap back around to the first span). I've
posted an example below.
I've tried using the .next() function, but that only returns the very
next element. I've also tried using .siblings(), but that gives me
all of the siblings that are spans, not just the next one. One thing
to keep in mind is that the actual page I am doing this on will have
hundreds of these div sections, so accessing spans by ID is not
useful. It needs to be able to programmatically find the next sibling
span.
html
head
titleTEST/title
script type=text/javascript src=http://code.jquery.com/jquery-
latest.pack.js/script
script language=JavaScript
$(function()
{
$('#span1').bind('click', function()
{
// GET THE NEXT SPAN HERE
});
});
/script
/head
body
div id=div1
span id=span1SOME TEXT/spanbr /
a href=http://www.google.com;GOOGLE/abr /
spanMORE TEXT/spanbr /
divtextarea name=/textarea/div
spanA LITTLE MORE TEXT/span
/div
/body
/html