This is the area where jQuery rules the roost. Or so everything I've read tells me. So, how does Dojo stack up?
Still running this in parallel with Kyle's series:
Setting the contents of an element
// Convenience function to hide query details
var element = dojo.byId('whatever');
element.innerHTML = "Change to this";
Or you could chain it jQuery style:
dojo.byId('whatever').innerHTML = "Change to this";
Really just a matter of personal preference and what you find more readable.
- Adding a new html element
var l = dojo.byId("list");
var li = document.createElement("li");
li.innerHTML="Three";
l.appendChild(li);
- Removing content
li = dojo.byId("garbage");
dojo._destroyElement(li);
- Setting css properties (actually, there are a ton of helper functions for setting individual styles, but here's the generic case):
node = dojo.byId("whatever"); // or use dojo.query
dojo.style(node, "color", "salmon");
- Iterating over the matched set
When you use a dojo query (using CSS3 selectors), you can manipulate all the results automatically:
l = dojo.query("li");
l.style("border", "medium double black");
jQuery wins this one hands down. But you probably wouldn't be doing much of this sort of thing with dojo anyway. You'd be too busy working with higher level abstractions.