is there any way in which javascript identifies if the html object is a select or an input?

1

I am developing a tool on a web page that has several forms for filling information, my query is if it is possible with javascript to differentiate between a select or an input.

I appreciate the help

    
asked by Alvaro vargas astorga 08.05.2018 в 15:41
source

1 answer

0

It's very simple, all the elements have their name saved in the tagName attribute

let c1=document.getElementById('campo1');
let c2=document.getElementById('campo2');

console.log('es un',c1.tagName)
console.log('es un',c2.tagName)
<input id="campo1"/>
<select id="campo2"><option value="valor">Algo</option>
    
answered by 08.05.2018 / 15:47
source