admin管理员组

文章数量:1190563

How to select a node after $(this) that matches a certain selector?

eg:

<textarea id="foo"></textarea>
<a href="#">someLink</a>
<a href="#">someOtherLink</a>
<textarea id="bar"></textarea>

With out directly selecting #bar via $("#bar"), how can i select it from within #foo?

How to select a node after $(this) that matches a certain selector?

eg:

<textarea id="foo"></textarea>
<a href="#">someLink</a>
<a href="#">someOtherLink</a>
<textarea id="bar"></textarea>

With out directly selecting #bar via $("#bar"), how can i select it from within #foo?

Share Improve this question asked Dec 10, 2010 at 6:25 BabikerBabiker 18.8k28 gold badges82 silver badges127 bronze badges 2
  • What's the rule/selector you're trying to match on? textarea? – Paul Schreiber Commented Dec 10, 2010 at 6:27
  • @Paul Schreiber: The first next textarea. – Babiker Commented Dec 10, 2010 at 6:30
Add a comment  | 

2 Answers 2

Reset to default 25

Use the nextAll() method:

$("#foo").nextAll("textarea").first();

Or:

$("#foo").nextAll("textarea:first");

Or even:

$("#foo").nextAll("textarea:eq(0)");

Check out siblings()

$('#foo').siblings('textarea:first').addClass('found');

jsbin demo here

本文标签: