jQuery.data vs getAttribute

Edit on GitHub

jQuery.data vs getAttribute

Setup

var script = document.createElement('script');
script.src= 'https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.js';
document.body.appendChild(script);

var div = document.createElement('div');
div.setAttribute('data-whatever', 'someval');

Tests

  • jQuery.data

    jQuery(div).data('whatever')
  • getAttribute

    div.getAttribute('data-whatever')