开发者

match a label with particular class

开发者 https://www.devze.com 2023-02-16 01:06 出处:网络
I have following structure: <label></label><input type=\"text\" id=\"t1\" /><label class=\"a\">fsafs<label>

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('');
})
0

精彩评论

暂无评论...
验证码 换一张
取 消