-4

I have the following html:

<div class="item" data-value="100">Something</div>

Now, I am using the following to find this element:

$( "div[data-value=value]") 

Where value is "100". However, I don't think jquery sees the value as javascript object - I think it takes it as it is. How can I fix this?

uksz
  • 18,239
  • 30
  • 94
  • 161

3 Answers3

3

Using filter

var $item = $('.item').filter(function(){
   return $(this).data('value') == 100;
});
Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
1
$( "div[data-value=" + value + "]") 
Pier
  • 81
  • 4
1

Use concatenation

var value = 100;
$( "div[data-value='"+value+"']"); 
madalinivascu
  • 32,064
  • 4
  • 39
  • 55