Login Register

dojo.dom

Where has dojo.dom moved in 0.9?

I want to use sth. like this (below is 0.4)
var previousTR = dojo.dom.getPreviousSiblingElement(dojo.byId(rowIds[i]), "tr");

Thanx!
Sven

more info...

I'm also looking for info on what has become/will become of dojo.dom. On http://dojotoolkit.org/book/dojo-porting-guide-0-4-x-0-9/style-html-util..., it is said that the DOM apis have been totally gutted and replaced, but I cannot find any replacement for getNextSiblingElement anywhere. Many of the DOM functions are now living in dojox/data/dom.js, but that file has a warning that it is still around only for use by XmlStore and wires, and that it will be deleted once those two sub-projects are no longer dependent on it. So, what is a developer to do?

dojo.query

You may want start using dojo.query(). It will solve most of your dom navigation issues.

can it be done?

I'm playing around with the dojo.query stuff, and I can't figure out how to get a sibling from it. I have a DOM like so:

ul
- li
-- anchor
-- select
--- options...
-- span
--- stuff set by the selection of the above select

So, what I used to do was have an onchange for the select that used getNextSiblingElement(choice) to grab the span, then call removeChildren (also deprecated, apparently) on the span that it found, and then set up all the selection-specific options. Now, I can't figure out how to get that select. using dojo.query("*:before", choice) gives me all the options on the select. dojo.query("*:after", choice) gives the exact same thing. dojo.query("span:after", choice) gives me "undefined" (using Opera; maybe other browsers say other things?). I've even tried stupid things like dojo.query("li:root", choice), which gives me no result at all, but I really wouldn't expect it to. Any hints on how to use a query to select a sibling?

You'll need to take a look at the CSS3 Selectors spec.

The one issue with CSS3 selectors is that there's only one real axis of querying: descendant (the default in XPath). Getting a sibling requires that you traverse the tree manually, IIRC.

The CSS3 Selector spec is here:
http://www.w3.org/TR/css3-selectors/

A decent tutorial is here:
http://www.456bereastreet.com/archive/200601/css_3_selectors_explained/

...and lastly, dojo.query does not support most of the CSS pseudo-classes. The ones supported should be:

:first-child, :last-child, :empty, :nth-child

Hope that helps.

ok

I'll have a look at those; I'm not really a JS developer, so a lot of this stuff is pretty new to me. I liked dojo.dom a lot; it had a ton of really obvious convenience functions that made life easy for someone who doesn't have any idea how to use javascript. I guess I'll have to learn how to navigate the DOM myself now :)

Is there a good Javadoc-style manual on the built-in standard Javascript objects, global methods, stuff like that?

remove a node

What would be the best way to remove a dom node, inluding removing all registered events on it?

I now have to use node.parentNode.removeChild(nodeToRemove) ... but events are not cleared with that,I think.

I assume dojo.query isjust for querting, but not executing removal, right?

---
Sven Haiges
Subscribe to the Grails Podcast: http://hansamann.podspot.de/rss
Skype: hansamann

dojo.query returns a dojo.NodeList, which *does*...

...a lot of stuff, including orphan(), which is what you want here:

var removedNodes=dojo.query(cssSelectionString, someNodeContext).orphan();

...will get all of the nodes that match the cssSelectionString and remove them from their parents.

Events are a special case; I believe that they are not entirely removed but connect usually takes care of that plumbing for you. The only way you can remove connections manually is to maintain a list of handles and run disconnect on it first:

dojo.forEach(someHandles, function(item){
    dojo.disconnect(item);
});
dojo.query(cssSelectionString).orphan();