jQuery IE Namespace test
jQuery bug:
http://bugs.jquery.com/ticket/4208
I investigated this one a bit and found that nodes with a namespace created using document.createElement are
detectable in IE6/7/8 using an escaped jQuery selector:
div.appendChild(document.createElement('a:bc'))
$(div).find('a\\:bc').length // equals 1
But...
The same nodes created with the same namespace are not detectable
by IE6/7/8 when they are created with .html():
$('<div/>').html('<a:bc/>').find('a\\:bc').length // equals 0
Instead, those nodes are detectable without the namespace:
$('<div/>').html('<a:bc/>').find('bc').length // equals 1
Here's a proposed addition to $.support to detect this behaviour.
$.support.htmlnamespace = $('<div/>').html('<a:bc/>').find('a\\:bc').length && true;
It will be true if namespaces are properly recognised and false if not.
HTML
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css">
<script src="http://code.jquery.com/qunit/git/qunit.js"></script>
<doctype html>
<html>
<head>
<charset="utf8"/>
<title>jQuery Namespace Test page</title>
</head>
<body>
<h1 id="qunit-header">QUnit example</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup, will be hidden</div>
</body>
</html>
JavaScript
$(document).ready(function() {
module("Using .html('<a:bc/>')");
test("find('a\\\\:bc')", function() {
var value = $('<div/>').html('<a:bc/>').find('a\\:bc').length;
equals(1, value, "We expect to find the element with namespace");
});
test("find('bc')", function() {
var value = $('<div/>').html('<a:bc/>').find('bc').length;
equals(0, value, "We expect to not find the element");
});
module("Using document.createElement('a:bc')");
test("find('a\\\\:bc')", function() {
var div, value;
div = document.body.appendChild(div = document.createElement('div'));
div.appendChild(document.createElement('a:bc'));
value = $(div).find('a\\:bc').length;
equals(1, value, "We expect to find the element with namespace");
});
test("find('bc')", function() {
var div, value;
div = document.body.appendChild(div = document.createElement('div'));
div.appendChild(document.createElement('a:bc'));
value = $(div).find('bc').length;
equals(0, value, "We expect to not find the element");
});
});
/* Proposed addition to $.support:
$.support.htmlnamespace = $('<div/>').html('<a:bc/>').find('a\\:bc').length && true;
It will be true if namespaces are properly recognised and false if not.
*/