How to know the type of the DOM object

Asked

Viewed 1,665 times

1

I wonder if via JS or Jquery, there is a way for me to identify the type of DOM object I am manipulating.

For example, I make the following selector: $('#filtos select, #filtos input').each(function (index, obj).....);

Within this each I’ll have objects <select>, <input> of the kind text, checkbox among others. I would like to know if you have any property that tells me what kind of these elements.

  • 2
  • @Brunorb , that’s right thanks. Can answer the question without being like comment.

  • What do you need it for? Wouldn’t it be better to make two selectors separately? Or maybe you can use a common function instead of doing different things for each type of field.

1 answer

1


Wear something like that:

$('#filtos select, #filtos input').each(function (index, obj) {
    var $this = $(obj)

    var meu_elemento = $this[0].tagName;

     if (meu_elemento == 'input') {
          var meu_tipo = $this.attr('type');
     }        
});

http://www.w3schools.com/jsref/prop_element_tagname.asp

Browser other questions tagged

You are not signed in. Login or sign up in order to post.