I’m trying to find the form element type (i.e. textarea, input etc.) by only having its ‘name’ attribute. Is there any way of achieving this with jQuery?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Get the element by its name attribute:
Then get the first element with
[0]:Then get the tag name with
nodeNameand normalise it withtoLowerCase:In jQuery 1.6, you can do this slightly more beautifully (if a little more slowly) by using
prop:I don’t think this will be normalised, so you’ll need to do so yourself.