Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get name of an input field using jQuery?

Tags:

html

jquery

input

Creating a plugin in jQuery, I have to get the names of input fields on which events would occur.

Suppose:

<input type="text" name="name" />
<input type="text" name="age" />

Whether submitted or not doesn't matter. What I want is to get the name of the field.

I tried the following:

$('#ins').html($(this).attr('name').val());

#ins is the div, where I am writing the events such as a click was made on the input with name = name. This way I want to create a plugin which would guide me to get to know which fields are getting some events.

like image 223
Afzaal Ahmad Zeeshan Avatar asked Oct 10 '13 19:10

Afzaal Ahmad Zeeshan


1 Answers

You are bit right but when you trying to access attribute you have to use only the attr not the val().

$(this).attr('name')

The above code is enough to get the name of the event triggered elements name attribute.

like image 156
MSMOHAN Avatar answered Sep 20 '22 12:09

MSMOHAN