I-M-JM
I-M-JM

Reputation: 15950

match a label with particular class

I have following structure:

 <label></label><input type="text" id="t1" /><label class="a">fsafs<label>

Now I want a jquery which can match only those labels with class "a" and it should be after id "t1"

I also want clear content of that label

Please help

Upvotes: 0

Views: 1119

Answers (2)

BoltClock
BoltClock

Reputation: 723448

For selecting only one label.a that comes immediately after #t1, use +:

$('#t1 + label.a').text('');

For all sibling label.a elements that come after #t1 (i.e. on the same level), use ~:

$('#t1 ~ label.a').text('');

Upvotes: 7

JohnP
JohnP

Reputation: 50009

This should work for you

$(document).ready(function(){
   $('#t1').nextAll('label.a').html('');
})

Upvotes: 2

Related Questions