JQuery: check if a label exists by a specific name

check if a label for a specific name exists

Tell me if I want to find if such a label exists.

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

if then i need to implement some code.

+4
source share
5 answers

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

+2
source

Try

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

Try the following:

  $(document).ready(function(){ var name=$("label").attr("name"); }); 
0
source

All Articles