Created
July 21, 2010 13:57
-
-
Save paulspringett/484515 to your computer and use it in GitHub Desktop.
Plugin to allow easy read/write access to HTML5 data- attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.dataset = function(key, value) { | |
if(value != null) { | |
if($(this).attr('data-' + key)) { | |
$(this).attr('data-' + key, value); | |
return true; | |
} else { | |
return false; | |
} | |
} else { | |
return $(this).attr('data-' + key); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Given the initial HTML
Reading data attributes
Writing data attrbiutes