2

Given n html elements with data attributes such :

<div class="tpl" data-points="2"></div>
<div class="tpl" data-points="5"></div>
<div class="tpl" data-points="10"></div>
<div class="tpl" data-points="5"></div>

Given a JS variable such as :

foo=10;

How to select the element with data-points==foo; ? (which currently is 10 but may change)

What is the suitable selector ?

2

1 Answer 1

2
$('div.tpl[data-points=' + foo + ']')

jsFiddle example

Sign up to request clarification or add additional context in comments.

Comments

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.