Jakeones
Jakeones

Reputation: 39

How to join a template variable with brackets in js?

I got the function taking the input name as a parameter.

function getInputs(inputName) {
    return document.querySelectorAll(`input[name=${inputName}[]]`);
}

I want to join it to the brackets but it throws the exception

The input name looks like this

What am I doing wrong?

Upvotes: 0

Views: 77

Answers (1)

Scott
Scott

Reputation: 5379

function getInputs(inputName) {
    return document.querySelectorAll(`input[name="${inputName}[]"]`);
}

Surround your attribute selector value with quotes.

Upvotes: 1

Related Questions