1

My html looks like this

<div class="slds-col slds-size_1-of-1 slds-hide" data-controllinganswer="a1ZC2000000O2n3MAC" data-questionid="a1fC20000000VgXIAU" data-id="a1fC20000000VmzIAE" data-selectedanswer="a1ZC2000000O2zxMAC">

But when I try to do this

this.template.querySelector('[data-id="' + e.dataset.id + '"], .slds-show')

It still returns me an element, even though there is no class as slds-show. Is this the right way of using queryselector with multiple attributes?

1 Answer 1

4

The comma selector1, selector2 says that elements having selector1 or selector2 should match.

If you have a space selector1 selector2 it will match an element matching selector2 inside an element matching selector1, if you have selector1selector2 without space, then it matches only an element that matches both selector1 and selector2.

So your selector should be

this.template.querySelector('[data-id="' + e.dataset.id + '"].slds-show')
Sign up to request clarification or add additional context in comments.

1 Comment

Or, in a more classic writing - .slids-show[data-id="..."]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.