Reputation: 301
How can I select element with particular data attribute and special class with jQuery please ?
For example, I would like to select these elements:
<div data-roomid="55" data-status="NoData"></div>
<div data-roomid="55" data-status="Open"></div>
<div data-roomid="55" data-status="Close"></div>
But not this one:
<div data-roomid="55" data-status="Book"></div>
My try is the following one:
roomid = 55;
$('[data-roomid="'+ roomid +'"]').each(function(e) {
});
Thanks.
Upvotes: 1
Views: 156
Reputation: 268
Is this what you're looking for?
$('div:not([data-status=Book])[data-roomid='+ roomid +']')
Upvotes: 0
Reputation: 42360
You can use :not
selector - see demo below:
var roomid = 55, status = 'Book';
$('[data-roomid="' + roomid + '"]:not([data-status=' + status + '])').each(function() {
$(this).css({
color: 'blue'
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div data-roomid="55" data-status="NoData">NoData</div>
<div data-roomid="55" data-status="Open">Open</div>
<div data-roomid="55" data-status="Close">Close</div>
<div data-roomid="55" data-status="Book">Book</div>
Upvotes: 1