How To Find Out A Div's Name Attribute
How do I read the name of a div with javascript or Jquery? I have code that dynamically creates divs with the same name and appends an ascending number to make the div unique. ex:
Solution 1:
If this
refers to the div element then this.id
will give the id value, $(this).attr('name')
should give the name attribute value
Solution 2:
Solution 3:
Get the id for that particular div. Use attr and prop in jquery.
getId = $(this).attr('id');getName = $(this).attr('name');
Note : jQuery 1.6, the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior. As of jQuery 1.6, the .prop() method provides a way to explicitly retrieve property values, while .attr() retrieves attributes.
Solution 4:
Use .attr() to get value of an attribute for the first element in the set of matched elements.
var id = $(this).attr('id');
Solution 5:
If $(this)
refers to the div you are talking about, then
$(this).attr('id')
returns either div id or undefined,
$(this).attr('name')
returns either div name or undefined.
Post a Comment for "How To Find Out A Div's Name Attribute"