Thursday, 15 May 2014

JQuery: selecting element with specific data-attribute's value? -



JQuery: selecting element with specific data-attribute's value? -

given n html elements info 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 js variable such :

foo=10;

how select element data-points==foo; ? (which 10 may change)

what suitable selector ?

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

jsfiddle example

jquery jquery-selectors

No comments:

Post a Comment