Skip to main content

jquery on data-xxxx modified event?



Is there a way of catching the modification of a specific data attribute (i.e. 'data-whatever')? My first thought was to go with DOM mutation observer but was wondering if there's any 'easier' way through jQuery?




Comments

  1. if there's any 'easier' way through jQuery?


    There is no attribute change event.

    Be careful with those "DOM mutation" events, they are deprecated and not supported in all browsers as much as I know.

    Better solution is: When you toggle the data.* attribute call that function you want.

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...