Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Match input with multiple attributes selector

Tags:

javascript

I have an input element:

<input type='checkbox' name='abc' />

How can I select it with querySelector using both attributes?

I have tried the following query:

input[name="abc", type="checkbox"]

But unfortunately an error appeared:

Failed to execute 'querySelector' on...

like image 431
Patrickkx Avatar asked May 16 '26 18:05

Patrickkx


1 Answers

You need to enclose each individual property/attribute with it's own square brackets.

input[name="abc"][type="checkbox"]

console.log(document.querySelector('input[type="checkbox"][name="abc"]'));
<input type='checkbox' name='abc' />
like image 54
Tschallacka Avatar answered May 18 '26 07:05

Tschallacka