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.
Try this in the loop condition - $ ('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 the following:
$(document).ready(function(){ var name=$("label").attr("name"); });