user984621
user984621

Reputation: 48521

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

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

Upvotes: 0

Views: 65

Answers (2)

BrownieInMotion
BrownieInMotion

Reputation: 1182

You can actually do exactly that with querySelector:

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

Upvotes: 2

mykaf
mykaf

Reputation: 1414

document.querySelector("input#address")

Upvotes: 1

Related Questions