开发者

dojo problems with creating new dom nodes

I am trying to create a new node that is a child of an existing ul node I have in the document, but no matter how I proceed I seem to get an error. The following two ways are the ways I have tried:

var ul = dojo.query('#highlights ul').0;
dojo.place("<li></li>", ul);

and I get a message:

TypeError: refNode.appendChild is not a function

This message didn't make sense to me because on checking the value of ul I find that it is an element and it has two children already...I went on to try the more programmatic build allowed by dojo.create(); via the following lines:

var ul = dojo.query('#highlights ul').0;
dojo.create("li", null,开发者_JS百科 ul);

and this produced an error:

TypeError: doc is undefined

which is really baffling me since the ul element is defined...I decided that I should just try adding the same li element to the doc body, so I went and tried:

dojo.create("li", null, dojo.body());

which returned without error, but on checking the document source nothing changed....So is there something I am missing? I assume that I don't need to require any files to use these, is that an incorrect assumption? the load function that contains this code is in an external file to help me organize my code, could this be causing the problem?

this function is called in the dojo.addOnLoad block to prevent problems when called async, could this be part of the problem?


Your problem is that you're not getting the node from your query.

It should be:

var ul = dojo.query('#highlights ul')[0];

not

var ul = dojo.query('#highlights ul').0;

I'm surprised your browser didn't error on the dojo.query line.


Probably xenador forgot to enclose dom manipulations in dojo.ready. doc is underfined == Document wasn't ready.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜