javascript - Get dojo methods for a DOM element - Stack Overflow

I have 'this' pointing to a DOM element ( a div or a form ). I want to use dojo functions ove

I have 'this' pointing to a DOM element ( a div or a form ). I want to use dojo functions over that element. How will I do it.

Like in jQuery we do $(this).append() ....

is there anything like

dojo.foo(this).connect() 

or

dojo.connect(dojo.foo(this),"some", thing);

I have 'this' pointing to a DOM element ( a div or a form ). I want to use dojo functions over that element. How will I do it.

Like in jQuery we do $(this).append() ....

is there anything like

dojo.foo(this).connect() 

or

dojo.connect(dojo.foo(this),"some", thing);
Share Improve this question edited Jun 19, 2011 at 18:02 Matt Ball 360k102 gold badges653 silver badges720 bronze badges asked Jun 19, 2011 at 17:55 Boopathi RajaaBoopathi Rajaa 4,7292 gold badges33 silver badges53 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

In Dojo, you are much closer to JavaScript (the raw metal) than in jQuery.

So in Dojo, you just do:

dojo.connect(this, ...);

You don't have to "wrap" the DOM element with a class object (like jQuery's $) to use the functionalities. A lot of functionalities in Dojo are not exposed as prototype properties of a class object, but as simple functions under the dojo.xxx namespace system.

For example (assume "this" points to a DOM node):

dojo.connect(this, "onclick", foo, "bar");   // Connects a handler to the Click event on the DOM node, with the context (i.e. this) set to the object foo
dojo.attr(this, "href", "http://www.hello.");   // Sets an attribute on the DOM node
dojo.style(this, "display", "none");   // Sets the DOM node's style
dojo.addClass(this, "hello");   // Adds a class to the DOM node
alert(this.parentNode);   // You work the DOM nodes with raw JavaScript
dojo.empty(this);  // Empty all children in the DOM node
dojo.destroy(this);  // Destroy the DOM node and its children
dojo.place(this, someOtherNode);   // Put a DOM node as a child inside another node

Looping constructs:

dojo.forEach(array, ...);   // Instead of array.each(...) as in jQuery style

If you want to loop through a list of nodes, it actually looks like jQuery:

dojo.query('query string').filter(...).forEach(...);

Read the docs for more details.

I figured out a way that will work i guess. Don't know if it is the best solution..

Have to import NodeList-traverse to use functions like children, parent ... Reference: http://dojotoolkit/reference-guide/dojo/NodeList-traverse.html#dojo-nodelist-traverse

dojo.require("dojo.NodeList-traverse");

Reference: http://dojotoolkit/reference-guide/dojo/NodeList.html

var nl = new dojo.NodeList(this);

nl.parent();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745080755a4610110.html

相关推荐

  • javascript - Get dojo methods for a DOM element - Stack Overflow

    I have 'this' pointing to a DOM element ( a div or a form ). I want to use dojo functions ove

    12小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信