I have an id for a <tr id="tagTR">
Given the above, is it possible to find the next input:text
element regardless of any other mark up in between . Is there a jQuery selector that I can use for this scenario?
For example :
<tr id="tagTR">
</tr>
<tr id="tagRed">
<td> </td>
</tr>
<div>
<tr>
<td>
<input> // This is what I want to get to.
</td>
</tr>
</div>
You cannot have a
div
tag in betweenTR's
. It is not a valid markup.To find the
input
element from the referredtr
you can try this.@Cawas - nice solution, but I suggest to use it not excessive, because of
$('*')
is expensive ;-)Regardless of that, I extended it for my needs:
So if
returnItselfIfMatched
is settrue
it returns itself, if it matches the selector itself. Useful, if you don't know, which element is calling and you are searching for exactly itself.You can use "next":
I thought this question was very interesting. It seems others are reading this as, find the next input among siblings. But I read it as - find me the next input no matter what. I don't know if its in a sibling, a parent or a parent's sibling. This is what I came up with based on feedback I received from this question.
http://jsfiddle.net/GesSj/1
Check it out: moved this into a more complete question and answer
Based on the awesome answer by @mrtsherman, I wrote this more complete solution:
Then you can use it as this:
I would submit a PR for this on jQuery lib if I knew my code was properly optimized and if it was okay by Mr T Sherman there, meaning I think this should be a core method on jQuery! :P