jquerydomcross-browserdeprecateddom3

Replacement for DOM3 getUserData/setUserData methods


So we've got some old-school Firefox extension code that uses the DOM3 methods get/setUserData() to pass around data in the DOM. Unfortunately, these have been deprecated in DOM4, so Firefox is planning to drop support for them, and Chrome never supported them in the first place.

Is there a cross-browser replacement? jQuery's $.data seems to be an option, but 'pure' JavaScript would be preferable.


Solution

  • So in the end we decided to go with jQuery after all, the core library is only around 75k and it solves the problem very cleanly:

    element.getUserData('foo') --> $(element).data('foo')
    
    element.setUserData('foo', 'bar', null) --> $(element).data('foo', 'bar')