Question

I am just getting to know jQuery.

How do I get the 'name' of an element in an Html page?

1 Answers

Here is an example of using jQuery to get to the name of an element:

HTML:

<p id="#myid" name="myname">Inside text</p>

jQuery:

To get the name of the above element use jQuery attr() like so:

var name = $('#myid').attr('name');
alert('The name is ' + name);

This snippet will display the name in a small alert box.