in

Corey Roth and Friends Blogs

Group site for developer blogs dealing with (usually) Ionic, .NET, SharePoint, Office 365, Mobile Development, and other Microsoft products, as well as some discussion of general programming related concepts.

Not Necessarily Dot Net

Manipulating the DOM with Dojo

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:

  1. 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.
  2. Adding a new html element
    var l = dojo.byId("list");
    var li = document.createElement("li");
    li.innerHTML="Three";
    l.appendChild(li);
  3. Removing content
    li = dojo.byId("garbage");
    dojo._destroyElement(li);
  4. 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");
    
  5. 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.

Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add
2019.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems