Home > OS >  Javascript - how to get an element by ID and name?
Javascript - how to get an element by ID and name?

Time:11-04

This is how I detect an element by its ID:

var address = document.getElementById('address');

However, I'd want to specify that I want to detect only element with this ID (address) AND that the element is input, nothing else (eg. select).

So input#address would be picked up, but select#address would be ignored.

How do I do that?

Thank you in advance

CodePudding user response:

You can actually do exactly that with querySelector:

const address = document.querySelector('input#address')

CodePudding user response:

document.querySelector("input#address")

  • Related