Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get type of form element with jQuery

I have a form with some inputs and selects. I want to get the type of element on its click with jQuery. I know I can use attr("input") to get if the element is radio, checkbox or text but what about selects and textarea?

Is there a overall function like .type() to get it?

like image 658
hd. Avatar asked Feb 29 '12 07:02

hd.


1 Answers

Getting the element type (input, select, div, span etc):

var elementType = $(this).prop('tagName');

Checking for specific element type:

var is_element_input = $(this).is("input"); //true or false

Getting the input type (input type="button" etc)

var inputType = $(this).attr('type');
like image 71
adeneo Avatar answered Sep 29 '22 09:09

adeneo