$(function(){ $('a').click(function(){ $('#div').data('id', 'id'); console.log( $('[data-id]').length ); }); });