I have this element
<div class="messages selected" data-conversationId=""></div>
The data-attribute conversationId is set dynamically like so:
$(".messages").data("conversationId", conversationId);
I am having issues using a selector to select this element by the data attribute.
$(".messages[data-conversationId=4]")
Returns empty array. Interestingly:
$(".messages").data("conversationId")
returns 4
What is wrong with my selector?
4?$('.messages[data-conversationId="4"]').$('.messages[data-conversationId="4"]')should work?data()method which just update it's property not it's attribute.... so you need to usefilter()or update attribute value usingattr()method