Created
January 4, 2012 19:21
-
-
Save happyboredom/1561564 to your computer and use it in GitHub Desktop.
bonzo - convert .data() from a DOM element into URL encoded string (as with ".param()" in jQuery)
This file contains 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
/* | |
Takes data elements from an HTML tag and converts to a URL encoded string. | |
*/ | |
bonzo.aug({ | |
param: function () { | |
var str = []; | |
obj = this.data(); | |
for(var p in obj) | |
str.push(p + "=" + encodeURIComponent(obj[p])); | |
return str.join("&"); | |
} | |
}) | |
/* | |
example: | |
<a href="#" data-color="red" data-size="small">Car</a> | |
bonzo(qwery('a')).param() | |
Note: I am used qwery for DOM selectors. | |
returns: | |
"color=red&size=small" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment