Q:

How to compare data value in all class?

consider the following case (simplification):
<li class='dest_list' data-selval='A'><span>1</span></li>
<li class='dest_list' data-selval='B'><span>2</span></li>
<li class='dest_list' data-selval='C'><span>3</span></li>

Now I want to check if a variable exist in anyli. And I know I can do the following :
var needle = "D";
var found  = false;
$('.dest_list').each(function(){

       if($(this).data("selval") == needle)
           found = true;

});

But what I wonder is can I do that using a selector? Something like :
if($(('.dest_list').data("selval") == needle)

Is there any possible way to do that?

A:

You can write the attribute in the selector like this
$('.dest_list[data-selval="D"]')

or if you want to use a variable you can do this
$('.dest_list[data-selval="' + needle + '"]')

Documentation

A:

You can use attribute selector to achieve that.
Try,
if($('.dest_list[data-selval="D"]').length > 0){
  //found
}

A:

You can use the attribute selector:
// Test for existence of element
if($(".dest_list[data-selval='D']").length) {
     // li with selval A exists...
}

