Access $('selector').data in functions/objects

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-05-24T00:27:53Z Indexed on 2010/05/24 0:41 UTC
Read the original article Hit count: 631

Filed under:
|

How do I access values set by $.data() inside a function or object

       $('#timers').data('firsttimer', 100);


    //prints 100
    document.write($('#timers').data('firsttimer'));

    function blah(){
        //Prints nothing
        document.write($('#timers').data('firsttimer'));
    }

blah();

See this jsfiddle for easy access to test the code http://jsfiddle.net/JUfd8/

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery