I would like to store the default value of an element in that element’s jQuery.data() collection. Since I can’t do this…
$("#myElement").data('defaultValue', $(this).html());
… because $(this) does not give me a reference to #myElement, what is the most efficient way to do this? I’m trying to avoid selecting the element twice like this:
$("#myElement").data('defaultValue', $("#myElement").html());
There’s no sane way really other than to save the jQuery object in a temporary variable:
An altenative which is just one expression, but IMHO is much worse: