Can I use the data() function to store a dom element (or a jQuery element) onto another element? (see code below)
Does it store it by value or by reference? Is it good practice?
I want to be able to quickly and easily find the slave element (see code below) of a master element, like so:
$slave = $('.some .path .to .slave');
$master = $('.some .path .to .master');
$master.data('slave', $slave);
$master.click(function (){ $(this).data('slave').toggle() });
(obviously the code is stupid, but I’m actually looping through a lot of master and slave elements.)
You can store whatever you want, whether or not you should.
JS variables are references to objects, no? (That’s only partially rhetorical–what else would a DOM query return other than a reference? A deep copy?)