Dig into Dojo: DOM Basics

Dig into Dojo: DOM Basics

Tutorial Details
This entry is part 1 of 4 in the Dig into Dojo Session
Next »

Maybe you saw that tweet: “jQuery is a gateway drug. It leads to full-on JavaScript usage.” Part of that addiction, I contend, is learning other JavaScript frameworks. And that’s what this four-part series on the incredible Dojo Toolkit is all about: taking you to the next level of your JavaScript addiction.


Before We Begin

I should mention before we begin that the only prerequisite for this series is that you have at least a basic knowledge of JavaScript. If you’ve used another JS library before, you’ll be even better off. But, although I compare Dojo to jQuery a couple of times, you don’t need to know jQuery to be comfy in this class.

Prefer Visual Training?

And, one more thing: I’ll be producing a screencast for each one of these tutorials, covering everything in the written tutorials, and maybe a little bit more. The ‘casts are part of the Net Premium Subscription, so if you aren’t a member, sign up to get them and a metric ton of other incredible Premium content.


Meeting Dojo

Dojo Toolkit

Dojo is officially called the Dojo Toolkit. This is actually very fitting. Most other collections of lines of JavaScript available bill themselves as frameworks or libraries. In my mind, a framework is a more or less end-to-end solution for building good web applications, and a library is a collection of tools that assist you with a few specific (usually related) tasks. Dojo fits into both categories, and then some. It’s got all the DOM manipulation, events and animation helpers, and AJAX functions that you’d get with a library like jQuery. But there’s more, much more.

On your first few dates with Dojo, you won’t realize just how much there is to it. So, let me introduce you to the three main parts of Dojo:

  • Dojo Core: Dojo Core is the main, base functionality. Most of it is the kind of thing you’d get with jQuery. However, it also holds dozens of general-purpose language utilities, as well as the plumbing for the other parts of Dojo.
  • Dijit: Dijit is the UI library of Dojo; it’s an official sub-project, managed by separate people. In that way, it’s similar to jQuery UI. A lot of the functionality is similar to the kind of things you’d find in the jQuery UI Widgets library as well: Calendar pickers, combo boxes, and buttons. If you want to crank up your web forms a notch, you’ll find almost everything you need in Dijit. Dijit also contains some interesting layout tools.
  • DojoX: DojoX (Dojo extensions) is a collection of individual projects that, you guessed it, extend Dojo. It’s hardly an exaggeration to say that, “there a Dojo extension for that.” Incredible charting utilities? Check. Every type of data store you’d ever want, and then some? You bet. Even more form helpers to boost the ones available in Dijit? It’s here. It’s all here.

Getting Dojo

We’ll start, of course, by getting Dojo on the page. I want to tell you that Dojo isn’t like jQuery, because there are dozens of files that make up Dojo, Dijit, and Dojox. The reason I’m hesitant to say this is that you’ll say that jQuery isn’t just one file: there are all the plugins and extensions that are made for it. The difference with Dojo is that, all these extra parts are officially part of Dojo, and can be called into your webpage at any time.

However, right now, we only need the Dojo Base. This is a subset of Dojo Core, available in a single file. So, while you can download all of Dojo (and Digit and Dojox), or create custom builds of it with just the parts of it you want, we’re going to take the easy route and get the Base from the the Google CDN.

<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6.1/dojo/dojo.xd.js"></script>

So, create an index.html file and start with this little template:

<html>
<head>
    <title> Intro to Dojo, part 1 </title>
    <style>
	    .highlight {
  			background: yellow;
  			font-weight: bold;
  			font-size: 1.5em;
		}
	</style>
</head>
<body> 
    <h1> A Heading </h1>

    <ul id="nav">
      <li> <a href="/">Home</a> </li>
      <li class="highlight"> <a href="/portfolio"> Portfolio </a> </li>
      <li> <a href="/about">Abou</a> </li>
      <li> <a href="/contact">Contact</a> </li>
    </ul>

    <p> This is a paragraph (albeit a very <em>short</em> paragraph). Also, <a href="http://google.com">here&#39;s a link</a>. </p>
 	<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6.1/dojo/dojo.xd.js"></script>
</body>
</html>

I’ve included a bunch of elements in this little demo page. We’ll be using them as we explore Dojo.

I’ll mention one more thing before we get started: when you’re learning a library like Dojo, you’ll probably find it useful to view our testing page in your browser of choice and pop open the respective JavaScript console. Take any line of code in this tutorial and paste it into the console, and you’ll see what’s happening.


Finding Elements

In this tutorial, we’re going to be learning Dojo primarily as a replacement for jQuery, or whatever DOM-focused library you use. Of course, that’s hardly a floorboard in this Titanic, but it’s a good place to start. Once you’re comfortable using it in place of your normal library, we can go on to what makes Dojo unique.

The usual M.O. with these things is get it, use it; so, let’s start with finding DOM elements.

Dojo has a couple of methods for hunting through the DOM. The first one we’ll look at is dojo.query, which is very much like the jQuery (or $) method. Just pass it a CSS selector string, and it will find all the elements in your document that match the selector.

dojo.query("a"); 

Running that in a console, you’ll get a NodeList with 5 items. It holds the five anchor tags you’ll expect. What do you expect to get when you try dojo.query("p > a")? dojo.query can also take a root, or context element as a second parameter. As you might expect, this limits the scope of the query to elements inside that root element. So:

dojo.query("a", "nav"); // returns a `NodeList` of 4 <a>s

The root parameter can be either a DOM element, or a string that’s an ID of an element.

The returned NodeLists also have a query method, which finds nodes that match the selector that are children of the nodes in the original NodeList. For example:

dojo.query("a"); // a `NodeList` of 5 <a>s

dojo.query("p").query("a"); // a `NodeList` of 1 <a>

But wait, there’s more, as they say. There are two other Dojo methods for getting elements. If the element you want has an id attribute, you can use the dojo.byId method.

dojo.byId("nav");

If you try that out, you’ll notice that you don’t get a NodeList object back: it’s just a plain old DOM element. This will be important to remember.

One more, and that’s even more specific: dojo.body(). It returns the element, predictably.

Now, if there’s one “main thing” that most devs use their JS libraries for, it’s working with DOM elements. Of course, Dojo has all the facilities for this too, so let’s take the tour.


Creating Elements

We’ll start by creating elements, with dojo.create. First, you can simply just get a new DOM element like this:

var h = dojo.create("h2"); // <h2></h2>

Simple. But, usually, you want to do more. Well, you can pass an attributes object as a second parameter:

var h = dojo.create("section", { role: "banner", innerHTML: "Learning Dojo"});
// <section> role=​"banner">​Learning Dojo​</section>​

The dojo.create method can also add elements directly to the DOM. For that, we can add parameters 3 and 4:

dojo.create("p", { innerHTML: "Hi there!"}, dojo.body(), "first");

dojo.create("h1", { innerHTML: "Heading"}, dojo.query("h1")[0], "before");

The third parameter is called the reference node; our new node will be placed in the DOM relative to that element.

But where, in reference?

That’s where the fourth parameters, the position, comes in. By default (i.e., if you leave it out), it is “last”, which appends the new element to the reference node (as its last child). Your other options are these:

  • “first” prepends the new node to the reference node.
  • “before” and “after” put the new node before or after the reference node.
  • “replace” replaces the reference node with the new node.
  • “only” replaces all the child elements of the reference node with the new node.

Modifying Nodes

You don’t know it yet, but you’ve pretty much learned the dojo.attr method. Let’s formalize this introduction.

dojo.attr is used to get and set attributes on DOM nodes. Remember that attributes object that we passed as the second parameter to dojo.create? You can pass that as the second parameter to dojo.attr. The first parameter, of course, is the node that is having its attributes modified (or an id string):

var navUl = dojo.query("p")[0];

dojo.attr(navUl, { 
	onclick : function () { 
		alert("Learning Dojo!");
	},
	role: "banner",
	style : {
		backgroundColor: "red",
		fontSize: "2em"
	}
});

If you just want to set a single attribute, just pass the name as the second parameter and the value as the third:

dojo.attr("nav", "className", "module"); // first parameter is an id string

To get an attribute, only two parameters are required:

dojo.attr(dojo.byId("nav"), "id"); // "nav"

You can use the NodeList method attr in the same way:

var items = dojo.query("li");

items.attr("innerHTML"); // [" <a href="/">Home</a>", " <a href="/portfolio">Portfolio</a>", " <a href="/about">About</a>", " <a href="/contact">Contact</a>"]

items.attr({ className: "btn" });

One more thing: to remove attributes, you can use dojo.removeAttr and the NodeList counterpart to remove attributes from elements completely:

dojo.removeAttr("nav", "id");

dojo.query("#nav").removeAttr("id");

There are other ways to modify those nodes, though. How about dojo.addClass, dojo.removeClass, or dojo.toggleClass? You can use these to add, remove, or toggle a class or array of classes on single nodes:

var nav = dojo.byId("nav");

dojo.addClass(nav, "selected");

There are also NodeList counterparts for these methods:

dojo.query("li").removeClass(["selected", "highlighted"]);

Oh, and don’t forget about dojo.replaceClass and the NodeList version:

dojo.query("p").replaceClass("newClass", "oldClass");

Removing Nodes

Want to get rid of a node? Easy: pass dojo.destroy either a DOM node or an id string:

var navList = dojo.byId("nav");
dojo.destroy(navList);

// or, easier:

dojo.destroy("nav");

I should note that there’s no way to destroy a NodeList; dojo.destroy only accepts single nodes, and doesn’t have a NodeList counterpart method.

But let’s say you just want to take nodes out of the DOM, but not actually destroy them. After all, you might want to plug them in somewhere else, or when something else happens. This is where the orphan method comes in. This method is only a NodeList method:

dojo.query("li").orphan();

On our example page, this removes the four

  • s and returns a NodeList of them. If you’d only like to orphan certain nodes from original NodeList, pass is a filtering selector. Note that this filter only matches against nodes in the original NodeList, and not their children:

    dojo.query("li").orphan("li:first-of-type"); // will only orphan the first &amp;lt;li>

    While it isn’t removing an element, I’ll throw this in here: dojo.empty() will take a single node or id and remove everything inside it. Behind the scenes, Dojo is actually just doing node.innerHTML = "". There’s also a NodeList version of this method that, obviously, requires no parameters.


    Moving / Duplicating Nodes

    There are a couple methods related to moving or duplicating DOM nodes.

    You’ll find you’re already partly familiar with dojo.place, from dojo.create. It takes three parameters: the node, the reference node, and the position. As you might expect, these parameters play the same roles they do in dojo.create:

    var nav = dojo.byId("nav"),
        p = dojo.query("p")[0];
        
    dojo.place(nav, p, "after"); // moves `nav` to right after `p` in the DOM

    Following the trend of so many Dojo DOM method, there’s a NodeList method counterpart:

    dojo.query("p").place(dojo.body(), "first");

    Then there’s dojo.clone. While it will clone more than just DOM node structures, that’s what we’ll use it for right now: if you pass this method a reference to a DOM node, it will clone, or copy, that node and all its children. This’ll duplicate our example navigation ul, and put the copy at the top of the document:

    var u2 = dojo.clone( dojo.byId("nav") );
    
    dojo.attr(u2, "id", "nav2");
    
    dojo.place(u2, dojo.body(), "first");

    You can use dojo.clone to clone other JavaScript objects as well.

    var o1 = { one: "one"},
        o2 = dojo.clone(o1);
        
    o1 === o2; // false

    Then, there’s the NodeList method adopt. I’ll have to admit that, while this is an interesting method, I’m still not exactly sure where I would use it. Here’s what it does: it takes two parameters: a selector string or DOM node(s), and an optional position value, which has the same options as dojo.place (“last” as default, etc. ). Then, the adopt method will take the element(s) you passed in as the first parameter (or the elements in the DOM that match the selector) and position them relative to the first element in the NodeList. Then, it returns the adopted elements as a new NodeList. So, in our example page, this will replace all the children of the first <li> with the paragraph:

    dojo.query("li").adopt("p", "only");

    So, there’s that.


    Iterating over Nodes

    Since NodeLists are similar to arrays, you could use just a regular for loop to iterate over them. However, NodeLists have a forEach method:

    dojo.query("li").forEach(function (element, index, arr) {
    	// do your thing
    });

    As you can see, the callback function takes three parameters, the element, the index, and the array itself. If you want to loop over other arrays, you can use dojo.forEach in the same way, just passing that array as the first parameter:

    dojo.forEach([1,2,3], function (item) {
    	// act here
    });

    forEach returns the NodeList or array that you started with. If you want to return a changed array, you can use the map method. Whatever you return from the callback function will be in the array (or NodeList) returned at the end.

    dojo.map([1,2,3], function (item) {
    	return item * item;
    }); // [1, 4, 9]

    Somewhat related to this is filtering nodes out of a NodeList, with filter.You can just pass this method a CSS selector, and only elements that match it will be kept.

    dojo.query("li").filter(".highlight"); // NodeList with one <li class="selected">	

    However, filter can also take a callback function that receives three parameters: the current item, its index, and the array. If the function returns true, the element is kept; otherwise, it’s left out. A new NodeList of the kept elements is returned.

    dojo.query("li").filter(function (el) { 
    	return dojo.query("a", el)[0].innerHTML === "About"; 
    }); // returns a NodeList that holds only the list item with the text "About"

    Handily, there’s also a dojo.filter version that takes an array as the first parameter and the callback as a second.

    dojo.filter(["Nettuts", "Psdtuts", "Phototuts"],  function (el, idx, arr) {
    	return el.slice(0,1) === "P"
    }); // ["Psdtuts", "Phototuts"]

    Working with Events

    Let’s now talk about events with Dojo. And we will start with DOM events, since that’s usually what you’re using. let’s say we want to do something when our <h1> is clicked. There are several ways to do this, and we’ll discuss them all here.

    First, let’s assume we are handling an event that occurs on an element or elements that we have retrieved with dojo.query. We could use the onclick method that NodeList s have:

    dojo.query("h1").onclick(function () {
    	alert("Learning Dojo");
    });

    However, this is really just a “syntactic sugar” method. Behind the scenes, Dojo is using the connect NodeList method:

    dojo.query("h1").connect("onclick", function (e) {
    	alert("learning Dojo");
    });

    This method actually passes the job on to another method, dojo.connect; you’ll probably use this method directly when you’ve got a single DOM node that you want to handle an event on:

    var h = dojo.query("h1")[0]; // or dojo.byId("some_element"), for example
    
    dojo.connect(h, "onclick", function () {
    	alert("learning Dojo");
    });

    Notice how, each time we “move up a layer”, we add another parameter to the beginning of the method call.

    Let’s talk briefly about disconnecting events. When using the methods provided on a NodeList instance, there’s currently no easy way to disconnect the events. This is because dojo.connect returns a handle that is used in the disconnection of events. To disconnect an event, pass its handle to dojo.disconnect:

    var h = dojo.query("h1")[0],
    
    	handle = dojo.connect(h, "onclick", function () {
    		alert("learning Dojo");
    		dojo.disconnect(handle);
    	});

    If you put that in your console, and then click the <h1>, you’ll get an alert. Then the handler will be disconnected, so subsequent clicks won’t do anything.

    If you want to create your own events (or, using Dojo’s terminology, your own topics), you can use Dojo’s publish and subscribe methods. If you’re familiar with how other pub/sub systems work, you’ll have no trouble with this.

    To subscribe an topic, simply pass the name of the topic and the function that should run when the topic is published:

    dojo.subscribe("myTopic", function (data, moreData) {
    	alert(data);
    	console.log(moreData);
    });

    Then, you can publish the topic almost as easily:

    dojo.publish("myTopic", ["some data", "some more data"]);

    Notice that any data you want to pass to functions that subscribe to your topic gets put in an array and passed as a second parameter.


    Conclusion

    In this tutorial, we’ve covered probably 90% of the DOM functionality built into the Dojo Base file we’re getting from Google’s CDN. However, there’s more functionality to discuss. Before we get there, however, we’re going to have to learn about pulling in Dojo’s extra functionality. We’ll discuss that and much more in the next episode of this series.

    Have any requests for things you’d like to learn to do in Dojo? I always read the comments, so you know what to do!

  • Tags: dojo
    Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
    • http://digitale-avantgarde.com chp

      I’ve played around with the dojo toolkit and it’s a really cool javascript library. I came to use it, because it ships with the zend framework.

      However, there were 1 thing that made me come back to jQuery: Documentation.

      I found myself hours of hours digging into the dojo documentation (that is not always up-to-date and self-explanatory), searching the web, asking the chat or fired mails into the mailing list.

      On the other hand, jQuery is so widely used, it’s hard to imagine a problem noone ever had before you. Whatever it is, you type it into google and then find a stackoverflow answer within the first 3 google hits.

      Turned out, that matters.

      • Michael

        I’m totally with you on this. Dojo is powerful, but it’s like trying to fly a commercial airliner with the instruction manual for an RC plane.

        I’ll probably stick with jQuery for a very, very long time. It’s simplicity is it’s beauty, and it’s documentation is sublime. I can’t think of anything that Dojo does better.

      • http://kylehayes.info Kyle Hayes

        It’s worth to take another look at. The Dojo community is well aware of the documentation issue it has had in the past and they are working hard to improve it more and more everyday. As a developer for an a large international entertainment company, Dojo is the only toolkit that provides us with the enterprise scalability that we need.

        It’s out-of-the-box modularity is second to none, paired with its build system to make the code tiny. In addition, Dojo still feels like JavaScript at the end of the day, whereas my experience with jQuery I felt like I was writing a slightly different language. Not all logic in JavaScript boils down to a DOM selector.

    • okeowo aderemi

      i dont believe this. i have been screaming for a Dojo Tutorial long last though a bit late but better, yeah Jquery was my first but later switched to Dojo because of its modularity but yeah the documentation aint that easy to grasp compared to Dojo. but its a very good toolkit i use especially with Zend Framework, the dojo connect is so powerful

    • Okeowo Aderemi

      Dojo WishList Tutorials

      1.MVC with Dojo

      2. Yes the most confusing of all things create a build script not with Dojo Web Builder but the one with the Dojo Source. would consider this as an xmas gift. :)

    • cesar

      Thanks for this tutorial. I just started learning DOJO and it was a task. I completed a small project to see how good it is. I like DOJO but I am still deciding if I go back to Jquery as it seems that Jquery is easier and you can find tons of info if you stuck with Jquery.

      I think DOJO is great and hopefully they can get 2.0 soon. I think I will stick with DOJO for few more weeks to see how it goes. Keep those DOJO tuts please.

    • Jim

      OMG yes! please do a tutorial on doing a build, using the built-in build script etc.

      And I second the fact that the lack of reliable, or any, documentation is the number one drawback of DOJO. I would wager that this article will soon become the place to go for a DOJO introduction.

    • http://www.shaundunne.com Shaun

      I love the Dojo Toolkit and think it’s awesome. jQuery is great too, but there are just a few things that I think Dojo does better and some situations where it would be better suited.

      Unfortunately, so many developers ONLY know jQuery – some dont even know Javascript too well – and that leads to 99% of projects worked on using that library. It’s not a bad thing, just sometimes wished that I could use Dojo on projects more.

      Looking forward to the rest of the series Andrew, as always will be putting my subscription to good use with the videos.

    • Jim

      Can you also cover DIjits, creating new ones and their lifecycle methods?

    • PixelBarfingMachine

      “jQuery is a gateway drug. It leads to full-on JavaScript usage.” – LOL, most people I know who use jquery specifically use it because they can’t do vanilla javascript. If anything, it makes them dependent on pre-made stuff.

      Either way, Dojo sounds like just another dumb/cute named thing to learn. There will be a new one next week, and another the week after. Ad nauseam. In a few years, anyone who doesn’t know jquery, dojo, pepper, hotpie, roundBowl, torqueToolz, spiceSciptsFromSpace, goof, barf, hair, mud, dirt, clay, rock, dookie, etc, will be scrambled to just remember all their names.

      • DED

        It’s great to see Andrew writing a Dojo tutorial series. I’m looking forward to seeing the rest. I’ve been putting off digging very deeply into the toolkit and now there’s a good reason to learn it again.

      • Michael

        The same can be said for any library. I learned JavaScript way before using any libraries, as anyone should for any given language.

    • http://dylanschiemann.com/ Dylan

      Thanks Andrew for the excellent tutorial! It’s great to see some Dojo love on nettuts.

      Regarding the comments about documentation, I am curious if people have seen http://dojotoolkit.org/documentation/ , the collection of tutorials we’ve done this year ?

      For example Okeowo, have you seen http://dojotoolkit.org/documentation/tutorials/1.6/data_modeling and http://dojotoolkit.org/documentation/tutorials/1.6/build/ ? Or Jim, have you seen http://dojotoolkit.org/documentation/tutorials/1.6/hello_dojo/ , http://www.sitepen.com/blog/series/dojo-quick-start-guide/ , or http://www.sitepen.com/blog/2011/05/04/what-is-the-best-way-to-start-a-dojo-project/ , http://dojotoolkit.org/documentation/tutorials/1.6/understanding_widget/ or http://dojotoolkit.org/documentation/tutorials/1.6/recipes/custom_widget/ ?

      Note, I ask because I want to make sure we’re actively addressing documentation concerns. We need far more excellent resources like this tutorial series (and especially help in making the Dojo reference guide and API docs clearer), but I want to make sure people are seeing what Dojo has done this year, etc.

      • Okeowo Aderemi

        @dylan i was refering to before the latest documentation and tutorials, yes i have seen them and to be quite frank, i’ve got the copy of each articles because they are quite detailed tutorials that covers from beginning to end, which is cool especially the Dojox mobile app by David Walsh,

    • Dan

      Dojo sure does give us some more advanced tools than jQuery, and I’d love to see some tutorials on creating better widgets (templated) based on JSON data. I’d also love to see ways to better organize Dojo code.

    • http://www.shiftedwork.de/blog Daniel S

      Mh. So why is this ugly API better than jQuery? jQuery uses a CSS-style Selector Engine (sizzle), which fits perfect my needs.

      • vaff

        Because your only looking at the dom basics? … when it comes to more advanced stuff, dojo clearly wins with its module based framework.

        • Michael

          jQuery has modules (plugins) too. Are you referring to the build system?

      • http://www.github.com/dotink Matthew Sahagian

        Dojo API is hardly UGLY. In fact, I would wager it’s quite a bit more consistent than jQuery — and the resulting code is a LOT easier to read. For all the “power” and “quickness” that chaining 800 methods can have, most of the complex jQuery code I’ve seen tends to be unreadable.

        It is, of course, possible to create cleaner jQuery code, and indeed, it is usually the RIGHT way to do it, in the sense that if you’re going to re-use a query result, you should assign it to a var and then do your methods so you can use that var again.

        However, in my opinion, the fact that jQuery is designed the way it is promotes ugly, inefficient, and frequently overly complex code due to method chaining.

        In a lot of ways, Dojo gets you a lot closer to “real” javascript, with all the same nicities of browser problem abstraction. In addition, because it is a full stack framework that promotes incorporating extensions into its various parts rather than using an obtuse plugin style, many things are more consistent.

        With regards to the tutorial, the only thing that I ask is that the more advanced it goes that the programmatic solution is represented and none of the attribute hackery. That is my one huge disagreement and dislike of Dojo.

        • Okeowo Aderemi

          i feel your point, i’d rather understand Alien Language than read jQuery multiple chaining it’s so terrible, the last company i worked for asked me to adjust a jQuery plugin, it had loads of chaining, am still under the assumption that was a punishment for “something” i did.

    • Pong

      Thanks Dylan, I’m a Dojo user. And I know your guys put so much effort on it, thank you so much.

      I’m a dojo user for 1 year. And I love it so much.

      the UI, module, store concept, grid…………..yes, in honest the learning cure is a little bit higher than other library but if you put sometime on it and then you will know how beautiful it is, and the their concept is faster then others.

      There are quite a lot of document was added in these years but the examples inside is not enough.

      P.S. Dylan, is dojo is the first lib with grid->template->Store concept?

      • http://dylanschiemann.com/ Dylan

        @Pong, not sure if we were the first, but I know we’ve been doing this since at least 0.4 (2006), and it was on our original roadmap in 2004.

    • Chris

      People really need to check out the tutorials on dojotoolkit.org, while this gives a great intro – the tutorials on dtk are more focused and up to date! Much easier to read and use I think than the reference guides.

    • http://www.webflysoftware.com aumpaul

      Great useful article.Really nice idea.Thank you.

    • ram

      Thanks for this tutorial.
      I have used Sencha for RIA development. Could you please compare Dojo with Sencha?

    • mcgiwer

      Dojo Toolkit is a pain in the ass.
      I prefer jQuery much more. It’s much more useful.
      In Dojo, complex DOM manipulation is a really big problem with it.

      • Okeowo Aderemi

        i beg to differ,Dojo is not a pain in the ass,in anything thing Dojo Toolkit allows you write much more readable codes than jquery, even Dojo can be written in Jquery manner(chaining) yes it has a higher learning curve, but after you get to understand the concept u’ll love the Dojo Toolkit,

    • http://andrewburgess.ca Andrew Burgess
      Author

      Thanks everyone for the great responses! Sounds like people are going to like this series :).

      About Documentation: I can understand where people complaining about lack of documentation are coming from. When I was first starting to learn about Dojo, I felt similarly. But the more I looked around, the more I discovered that there’s really an overwhelming ton of documentation. I think maybe part of the problem people trying to learn Dojo are experiencing is that Dojo is huge, and there is more than one way to do almost everything, so where to start with the documentation can be pretty hard to figure out. When I started, I was looking for a roadmap-style tutorial, that would explain the “big picture” of Dojo, and then explain what order to learn different parts in. That’s what I’m trying to do with this series: I’m hoping that if you begin learning Dojo as a replacement for jQuery, or your favourite DOM-centric library, you’ll be more likely to stick with it, and move on to the more powerful parts.

      Also, thanks for the topic suggestions! They probably all won’t fit into this introductory series (especially the build script stuff), but I’ll keep them all in mind for future tutorials.

      • Okeowo Aderemi

        @Andrew i think the reason is that we were used to jQuery where we dive in and get results,so coming over to Dojo made it seem more difficult, i remember taking 2 months to learn basic JavaScript before jumping to Dojo, and when i did Dojo made sense,most people don’t really know JavaScript to being with so jQuery takes that burden off them now imagine them jumping to Dojo which has lots of design patterns and is Object Centric, it will be hard for Jquery users to cope immediately. which is why i subscribe to people knowing JavaScript well before jumping to a framework.

        • http://kylehayes.info Kyle Hayes

          Couldn’t have said it better myself, Okeowo! It seems the folks who have the hardest time switching to Dojo are the ones who don’t know JavaScript.

      • Michael

        There may be a lot of documentation out there, as I found when learning Dojo, but most of it was not of quality.

    • http://incisivepoint.com Jack

      DOJO is Rock i think.

      But, can you give some live demo in your tuts?

    • Wouter J

      First, I’ve learned jQuery and then MooTools. And I love MooTools!
      jQuery makes his own language of JavaScript. With the $ and lots of });.
      MooTools let JavaScript be itself and added some great features.

      DoJo is the same as MooTools, really cool and I want to learn more. I can’t waiting for the next tutorial.

    • http://www.umbraprojekt.pl mingos

      I do jQuery. I tried learning Dojo once, and it looked promising, the learning curve wasn’t too steep, but wasn’t flat either – just the thing for me. But I couldn’t find any resources explaining the use of Dojo for what makes jQuery such an attractive option to all newcomers: animations, fades, slides… I’d appreciate covering the eye candy related stuff in the tut :).

    • Sven

      I think it’s also worth mentioning http://www.sitepen.com/blog/2011/08/03/dojoon-new-event-handling-system-for-dojo/ when referring to event handling in dojo.

    • pong

      the dojo store concept is absolute a great concept. And I found Extjs starting to use it too.
      Once you use store with grid or tree, you will know why dynamic it is.

      @Dylan, I have some suggestion for dojo document.
      1. first of all combine dojotoolkit.org and dojocampus.org into one site, I think most of the new user are confuse about it
      2. php.net document has a great function, user may leave message on their document. So user can share their experience and learning from each other.
      3. acutally dojotoolkit.org/community/ has many great experience. but sadly there are no classification. I suggest replace it by a forum. sepearte into
      dojo
      -dojo.array
      dijit
      -form
      -textbox
      ……
      dojox,
      it should be easier to found some old post related to the widget.

      I hope that it is a good for dojo…..^^

    • Michael

      I’ve used Dojo and jQuery, and I’ve yet to find something I like more in Dojo than jQuery. Libraries like this are supposed to make our programming lives easier by abstracting out a lot of the basic utility work and boilerplate, and I just don’t feel like Dojo accomplishes that very well. You should absolutely know how to write all the things Dojo and jQuery perform for you before using them, but when I decided to use a library to make my life easier and faster, I expect that library to be easy to use and fast to learn. I didn’t get that with Dojo. At the time, it took me about two hours to figure out how to make a simple XHR to retrieve and parse some XML, since the documentation assumed you would be using JSON. I was able to do this in jQuery in about five minutes.

      • Okeowo Aderemi

        Actually Dojo has a higher learning curve, i’d be sure the next time you give it a another go, it’d be a lot less difficult than before,its normal with any language.

    • bonnie

      Hi, all I have a tab menu of which I want to change the color of the text when one of the tab is selected and leave the other tabs unchanged.

    • Jas

      can we move the div which is already placed on the dom node to other place where ever we needed?