Is there any function to check if an input has a specific name in jquery, like we check the existense of a class using hasClass()
?
For example if I have an input
<input type="checkbox" class="col_control" checked="checked" name="sr_column" data-columnno="0" />
so that I can check hasName("sr_column")
and it returns true
el.name == 'text'
No need for any jQuery! If you do have a jQuery object, use jq_el[0].name == 'text'
instead.
Of course you can also use jQuery to access this, using either jq_el.prop('name')
or jq_el.attr('name')
(it's available both as a property and an attribute).
If you want jq_el.hasName(...)
, you can define the function like this:
$.fn.hasName = function(name) {
return this.name == name;
};
Try this also
var name = $("#id").attr("name");
OR
var name = $("#id").prop("name");
if(name=="sr_column")
{
//your code
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With