Derek
Derek

Reputation: 12388

Dojo equivalent to jQuery.text function?

What is the Dojo equivalent to $("...").text("asdf") and $("...").text()?

Also is there a wiki or site that provides dojo equivalents of jQuery functions?

Upvotes: 5

Views: 2636

Answers (4)

Mike Schall
Mike Schall

Reputation: 5899

You are looking for the dojo/dom-prop module. If you look at the source, there is special handling for the textContent property if the current browser does not support it.

    if(propName == "textContent" && !has("dom-textContent")) {
        ctr.empty(node);
        node.appendChild(node.ownerDocument.createTextNode(value));
        return node;
    }

Your code would look like the following:

domProp.set(node, "textContent", "hello world!");

or

domProp.get(node, "textContent");

Upvotes: 1

yongsung.yoon
yongsung.yoon

Reputation: 5589

A similar function in dojo is NodeList.text()

http://dojotoolkit.org/reference-guide/1.7/dojo/NodeList-manipulate.html#text

You can use like below.

dojo.query("#id").text("asdf");
var txt = dojo.query("#id").text();

Upvotes: 3

Starx
Starx

Reputation: 79049

Use can do this as

dojo.query('#yourdiv')[0].lastChild.textContent = 'text';
var text = dojo.query('#yourdiv')[0].lastChild.textContent

Upvotes: -1

Ry-
Ry-

Reputation: 225263

Just append a node to the element:

someElement.appendChild(document.createTextNode('asdf'));

You also might need to clear it beforehand:

while(someElement.firstChild) someElement.removeChild(someElement.firstChild);

As for getting the text, I don't know if there's a direct equivalent but you probably won't need one. Just read the nodeValue of the element's firstChild.

Upvotes: 0

Related Questions