1

I'm trying to store some data in DOM Elements ($.cache) on my plugin but I am facing some problem as mentioned below...

$(_buelement).data('yazi') returns undefined on metodlar.gizle but it works on metodlar.goster where I store the data.

In my plugin metodlar.goster initiates on onMounseIn and metodlar.gizle onMouseOut.

            $.fn.balon = function( metod, girdi ) {
                var _bu = this;
                var metodlar = {
                    goster : function(  ) {

                        return _bu.each(function ( ) {
                            var _buelement = $(this);
                            s.pozisyonAl(_buelement);

                            s.balon.fadeIn(300);
                            $.data(_buelement,{'balon' : s.balon,'yazi':'heyho'});

                        })
                    },
                    gizle : function( ) { 

                        return _bu.each(function ( ) {

                            var _buelement = $(this);

                           $(_buelement).data('yazi');

                        })
                    }
                }


                });

Finally I ran some debug and found out the metodlar.gizle is just works fine but data is still undefined.

Here's Fiddle Link : http://jsfiddle.net/4FfWz/4/

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Lupus
  • 1,519
  • 3
  • 21
  • 38

2 Answers2

2

Try changing the way you store the data in goster:

_buelement.data({'balon' : s.balon,'yazi':'heyho'});
pete
  • 24,141
  • 4
  • 37
  • 51
  • $.data(_buelement,{'balon' : s.balon,'yazi':'heyho'}); it worked but is this kind of declarations wrong? – Lupus Feb 05 '12 at 15:51
  • With `$.data(_buelement,{'balon' : s.balon,'yazi':'heyho'});`, `_buelement` is being used as the key to store the data, which makes retrieval problematic because it is a jQuery object. – pete Feb 05 '12 at 15:53
  • @pete That's not quite correct. `$.data` is the low level utility that's used by jQuery and it takes an element as the first argument. However, it doesn't support the "object as key/value pairs" syntax like `element.data()` does. – Ates Goral Feb 05 '12 at 16:01
  • The code also had a typo where "method" was used instead of "metod" somewhere. – Ates Goral Feb 05 '12 at 16:02
  • Also, here's a slightly cleaned-up version of your fiddle that actually works: http://jsfiddle.net/qJdEs/1/ – Ates Goral Feb 05 '12 at 16:04
  • Ateş pete'e söylediğini daha rahat anmayabilmem için Türkçe anlatabilir misin? – Lupus Feb 05 '12 at 16:39
0

Try this:

gizle : function( ) { 
   return _bu.each(function ( ) {
          var _buelement = $(this);
          _buelement.data('yazi');
           })
}
naresh
  • 2,113
  • 20
  • 32
  • @Lupus can you please put your code on jsfiddle and paste that link as part of your question.. – naresh Feb 05 '12 at 15:32