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
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('');
This should work for you
$(document).ready(function(){
$('#t1').nextAll('label.a').html('');
})
精彩评论