-
-
Save nathanhammond/a1defd74d3710ef82a4e to your computer and use it in GitHub Desktop.
Safari $('script').attr('event'); Bug
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>Safari $('script').attr('event'); Bug</title> | |
<script src="http://code.jquery.com/jquery-git.js" type="text/javascript"></script> | |
<script id="myscript" event="eventattributecontent" src="https://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js" type="text/javascript"></script> | |
</head> | |
<body> | |
<h1>Safari $('script').attr('event'); Bug</h1> | |
<p>This bug occurs when trying to use the jQuery .attr() on a script tag to access an attribute named "event". This page tests that scenario.</p> | |
<h2>Script Being Included</h2> | |
<script id="myscript" event="eventattributecontent" src="https://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js" type="text/javascript"></script> | |
<h2>Test Code</h2> | |
<pre> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
// DOM Method | |
var dom = document.getElementById('myscript').getAttribute('event'); | |
console.log('DOM: "' + dom + '"'); | |
// Direct attribute access. | |
var direct = document.getElementById('myscript').event; | |
console.log('Direct: "' + direct + '"'); | |
// jQuery .attr() | |
var jqueryattr = $('#myscript').attr('event'); | |
console.log('jQuery .attr(): "' + jqueryattr + '"'); | |
}); | |
</script> | |
</pre> | |
<h2>Results</h2> | |
<p>The expected result is the string "eventattributecontent". The actual result is an empty string. Occurs in the latest version (from http://code.jquery.com/jquery-git.js).</p> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
// DOM Method | |
var dom = document.getElementById('myscript').getAttribute('event'); | |
console.log('DOM: "' + dom + '"'); | |
// Direct attribute access. | |
var direct = document.getElementById('myscript').event; | |
console.log('Direct: "' + direct + '"'); | |
// jQuery .attr() | |
var jqueryattr = $('#myscript').attr('event'); | |
console.log('jQuery .attr(): "' + jqueryattr + '"'); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment