Ticket #3849 (assigned defect)
dojo.query does not work on imported nodes
| Reported by: | guest | Owned by: | alex |
|---|---|---|---|
| Priority: | normal | Milestone: | future |
| Component: | Core | Version: | 0.9 |
| Severity: | normal | Keywords: | |
| Cc: | keithpk@… |
Description (last modified by bill) (diff)
- Version: 0.9beta
- Browsers: FF 2.0 (probably more)
- Contact: keithpk at gmail dot com
- Note: The issue was posted in the forums, and no one has responded, so I'm filing a ticket.
- Description: In short, if you use import node to import some html from another document dojo.query can not find those nodes. The standard document.getElementById can though, so I'm not sure where the bug is. I have written a simple test case to reproduce this, which uses dojo.parser to show that the parser can not find/query for the inserted node. When you run this test, you will see that the first two buttons parse fine, the 3rd button, however, does not. Note: it will only work on FF, as DOMParser is not supported in IE.
<html>
<head>
<title>Dojo: Hello World!</title>
<link rel="stylesheet" type="text/css" href="js/dojo/dijit/themes/tundra/tundra.css"/>
<script type="text/javascript" src="js/dojo/dojo/dojo.js" djConfig="parseOnLoad: true">
</script>
<script type="text/javascript">
dojo.require("dijit.form.Button");
dojo.require("dojo.parser");
function onPageLoad()
{
// Create a separate document var text = "<doc xmlns="http://www.w3.org/1999/xhtml"><button dojoType="dijit.form.Button" id="test3">Test3</button></doc>";
var parser = new DOMParser();
var doc = parser.parseFromString(text, "text/xml");
// Get the button from the document
var button_element = doc.getElementById("test3");
// Import the button node into our document
var import_button = document.importNode(button_element, true);
// Insert it into our document
var dom_insert_node = document.getElementById("dominsert");
dom_insert_node.appendChild(import_button);
// The parser can not find it
dojo.parser.parse();
// Look it up in the document. Get element by id can find it just fine
var lookup = document.getElementById("test3");
// Choose your output method
console.log(lookup);
//alert(lookup);
}
</script>
</head>
<body onload="onPageLoad()">
<button dojoType="dijit.form.Button" id="test1">Test1</button>
<div>
<button dojoType="dijit.form.Button" id="test2">Test2</button>
</div>
<div id="dominsert">
</div>
</body>
</html>
Change History
Note: See
TracTickets for help on using
tickets.