Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7409959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:09:37+00:00 2026-05-29T06:09:37+00:00

I need to find the input type for radio buttons, text, and selects. Its

  • 0

I need to find the input type for radio buttons, text, and selects. Its easy to find the input type of anything with <input type="x"> since $(this).attr("type") would return x

My issue is that I need to support <select> elements, which dont have the type attribute. The end goal is to do return either radio, text, or select.

I thought of doing something like this, but I was curious if there’s a better way:

if ($(this).tagName == "input") {
    var result = $(this).attr("type");   //returns radio or text (the attr type)
} else {
    var result = $(this).tagName;        //returns select (the element type)
}

Thanks all!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:09:38+00:00Added an answer on May 29, 2026 at 6:09 am

    You can do this (fiddle here), make some sort of easy to use plugin:

    $.fn.getType = function(){ return this[0].tagName == "INPUT" ? this[0].type.toLowerCase() : this[0].tagName.toLowerCase(); }
    

    And use it like this

    $(".element").getType(); // Will return radio, text, checkbox, select, textarea, etc (also DIV, SPAN, all element types)
    $(".elList").getType(); // Gets the first element's type
    

    Which will get the type of the first element which is selected.

    Other info

    If you just want to have some selectors you can use this:

    $("input:text, input:radio, select");
    

    Or select all form controls (more info):

    $(":input") // can return all form types
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Dont worry we dont need to find out any bug in this code. Its
I'm working on a CSS file and find the need to style text input
I have several radio button that look like this: <div id=TheOptions> <input type=radio name=mylist/>option
I have a need to find and manipulate <input type=checkbox> from a table. At
I need to expose some input fields based on what properties I find for
So i need to do a find by id or email. The input can
When a user clicks on my radio button: <input type=radio name=allselect onClick=javascript: _select('none'); />
Given the following HTML fragment: <span name=foo class=foo-class> <input name=foo value=0 id=foo2_0 type=radio> <label
I have something like this: $('#find').click(function() {... I need to also add to that
This is homework, but I need a nudge. I can't find how to sort

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.