Skip to content

Making jQuery.data() selector aware

When using jQuery.data() to interact with data-attributes selecting elements with that attribute will not work. jQuery('.selector').data('name'); reads the data-name="foobar" attribute from a DOMElement. This attribute could be used in a selector, say jQuery('[data-name="foobar"]').hide(). But if you use jQuery.data() to set or update such an attribute, your selector would fail.

Continue reading "Making jQuery.data() selector aware"

Making jQuery.data() selector aware

When using jQuery.data() to interact with data-attributes selecting elements with that attribute will not work. jQuery('.selector').data('name'); reads the data-name="foobar" attribute from a DOMElement. This attribute could be used in a selector, say jQuery('[data-name="foobar"]').hide(). But if you use jQuery.data() to set or update such an attribute, your selector would fail.

Continue reading "Making jQuery.data() selector aware"