[ 9 posts ]

Vovan

  • Username: Vovan222
  • Joined: Sun Jan 09, 2011 4:51 am
  • Posts: 40
  • Offline
  • Profile
Tags:

Internal storing data in DOM element

Post Posted: Mon Jun 06, 2011 1:10 am
+0-
Hello YUI users. I like to work with YUI library but sometimes I have to use JQuery library. JQuery allows to store any data in a DOM element by using data() method. Something like this:
Code:
$('body').data('foo', 52);
window.alert($('body').data('foo')); // 52

It's very useful for me and I want to know is there in YUI such function ?

Alberto Santini

YUI Contributor

  • Offline
  • Profile

Re: Internal storing data in DOM element

Post Posted: Mon Jun 06, 2011 3:34 am
+0-
Hello Vovan.

A working example (http://jsfiddle.net/d83zV/):

YUI().use("node", function (Y) {
var myNode = Y.one("#test");

myNode.setData('foo', 52);
alert(myNode.getData('foo')); // 52
}

See also the reference:
http://developer.yahoo.com/yui/3/api/No ... od_getData
http://developer.yahoo.com/yui/3/api/No ... od_setData

Hope that helps,
IceBox

P.S.: Ops... it is for YUI 3... :)

Vovan

  • Username: Vovan222
  • Joined: Sun Jan 09, 2011 4:51 am
  • Posts: 40
  • Offline
  • Profile

Re: Internal storing data in DOM element

Post Posted: Mon Jun 06, 2011 3:48 am
+0-
Hello Alberto.
Thank you for the reply. Can I use it in YUI2?

Alberto Santini

YUI Contributor

  • Offline
  • Profile

Re: Internal storing data in DOM element

Post Posted: Mon Jun 06, 2011 3:53 am
+0-
Hello Vovan.

In YUI 2 there is "data" property.

See the reference:
http://developer.yahoo.com/yui/docs/YAH ... perty_data

Regards,
IceBox

Vovan

  • Username: Vovan222
  • Joined: Sun Jan 09, 2011 4:51 am
  • Posts: 40
  • Offline
  • Profile
Tags:

Re: Internal storing data in DOM element

Post Posted: Mon Jun 06, 2011 4:46 am
+0-
Thank you Alberto. So can use it something like this?
Code:
var el = document.getElementsByTagName('body')[0].data('foo', 52);

And how can I receive this value?

Alberto Santini

YUI Contributor

  • Offline
  • Profile

Re: Internal storing data in DOM element

Post Posted: Mon Jun 06, 2011 5:38 am
+0-
Hello Vovan.

It seems YAHOO.widget.Node should be a TreeView node.
So it doesn't help in this context.

At the moment I have no solution for YUI 2.

Regards,
IceBox

Vovan

  • Username: Vovan222
  • Joined: Sun Jan 09, 2011 4:51 am
  • Posts: 40
  • Offline
  • Profile

Re: Internal storing data in DOM element

Post Posted: Mon Jun 06, 2011 6:31 am
+0-
Too bad. Ok can I use YUI3 in my YUI 2 project to use this feature only?

Alberto Santini

YUI Contributor

  • Offline
  • Profile

Re: Internal storing data in DOM element

Post Posted: Mon Jun 06, 2011 7:01 am
+0-
Hello Vovan.

You can use YUI2 in 3:
http://developer.yahoo.com/yui/3/exampl ... ompat.html

Hope that helps,
IceBox

Vovan

  • Username: Vovan222
  • Joined: Sun Jan 09, 2011 4:51 am
  • Posts: 40
  • Offline
  • Profile
Tags:

Re: Internal storing data in DOM element

Post Posted: Mon Jun 06, 2011 10:06 pm
+0-
Thank you Alberto. But my project in YUI2 whole
  [ 9 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum