Another Question About .data()

Another Question About .data()

Say you have a button A that brings up a dialog box.  And the dialog box itself has a button B.

When the user clicks button A, you want to store some data that you will use later (when the the user eventually clicks button B).

I'm using the .data() function to store the data on button B itself. However, it's not working.  The data is not available in the handler for button B.

I store the data as follows:

      $('#buttonB').data('myData', theData);

Button B looks like this:

      <Button onclick="handleButtonBClick(this)">

You see where I'm going with this, don't you?  Here is the handler for button B:

      function handleButtonBClick(button) {
            var theData = $(button).data('myData');      // undefined!
      }

Obviously I'm attaching the data to a jQuery selector, but what's coming into the argument of button B's handler is an HTML element.  But I was expecting the jQuery wrapper that I was using to take care of that for me.  

I could of course just find the button again:

      var theData = $('#buttonB').data('myData');

But this seems kind of lame to have to search the DOM again, even though we already have the element.

Please kind coders, in your response to me, don't yell at me about unobtrusive JavaScript or the like.  There are reasons that I'm attaching the handler to button B in the markup.

Thanks.