Skip to content

Instantly share code, notes, and snippets.

@treasonx
Created August 8, 2012 08:45
Show Gist options
  • Save treasonx/3293539 to your computer and use it in GitHub Desktop.
Save treasonx/3293539 to your computer and use it in GitHub Desktop.
Setting Data Attributes
//Incorrect
jQuery(document).ready(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://ardrone.swoop.com/js/spxw.js"; // use this for linked script
//The following will not properly set the required data attributes properly
script.attributes['data-domain'] = 'SW-XXXXXX-X';
script.attributes['data-theme'] = 'red';
script.attributes['data-serverbase']= 'http://ardrone.swoop.com/';
document.body.appendChild(script);
});
//Correct
jQuery(document).ready(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://ardrone.swoop.com/js/spxw.js"; // use this for linked script
script.setAttribute('data-domain', 'SW-XXXXXX-X');
script.setAttribute('data-theme', 'red');
script.setAttribute('data-serverbase', 'http://ardrone.swoop.com/');
document.body.appendChild(script);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment