I have an Element with the custom attribute data-badge="1" that looks like this:
<div id="badge" data-badge="1">
<span></span>
</div>
Now I have some css styling the :after element of this divs chils-span. But as soon as the attribute data-badge is zero, I want to hide the :after element. So naturally I added this to the CSS
#badge span:after {
display: block;
content: " ";
...
}
#badge[data-badge="0"] span:after {
display: none;
}
This works quite well if I load the page, but as soon as I change the "data-badge" attribute using jquery, the element will no longer be hidden. What can cause this?
Thank you for your help
EDIT: Due to a request, here is the Jquery-Code aswell:
$(".button").click(function(){
$("#badge").data("data-badge","0");
});
(Of course there is way more jquery-code but this is literally the only part, that has anything to do with this attribute. And the problem occurs also, if the data-badge attribute is changed via jquery in the browser-console)
$(...).data('badge', '0'), jQuery modified thedatasetof the element, not the attribute you're willing to change. You'll have to use$(...).attr('data-badge', '0')insteadprop,attr,data, ...clickcallback actually runs?