Search code examples
javascriptjquerydom

Check if DOM Element is a checkbox


How can I check if a given DOM element is a a checkbox.

Scenario:

I have a set of textboxes and checkboxes in which the values are assigned dynamically. I don't have a way to identify if the DOM element is a checkbox or a textbox.


Solution

  • If you're using jQuery, you can use the :checkbox pseudo-class selector along with is method:

    if($("#that-particular-input").is(":checkbox")) {
    }