最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery : check if label by a specific name exists - Stack Overflow

programmeradmin1浏览0评论

check if label by a specific name exists,

Say if i want to find if such label exists

<label onClick='javascript:someMethod()' name="label_name">*some text*</label>

if so then i need to implement some code.

check if label by a specific name exists,

Say if i want to find if such label exists

<label onClick='javascript:someMethod()' name="label_name">*some text*</label>

if so then i need to implement some code.

Share Improve this question asked Apr 19, 2013 at 9:04 GarryGarry 3061 gold badge7 silver badges24 bronze badges 1
  • Do you want to know if does exist a Label with name="label_name" ? or if does exist a label with some text? – Magico Commented Apr 19, 2013 at 9:33
Add a comment  | 

5 Answers 5

Reset to default 6

Try This in condition loop -- $('label[name="label_name"]').length

Try

var x = $('label[name="label_name"]');
if(x.length){
    //label exists
}
if ($('label[name="label_name"]').length) {
    alert('Label exists');
}
if($('label[name="label_name"]').length)
{
    //code
}

Try this:

 $(document).ready(function(){
        var name=$("label").attr("name");
    });
发布评论

评论列表(0)

  1. 暂无评论