Is it possible to change the contents of elements when they, or a part of the text within them, is selected then reverting them back when they are deselected?
The aim being that when they are copied to the clipboard the alternate value is copied.
The html looking something like this:
<p>Today is the <span class='date' value='18/03/2009'>18th of March</span>.</p>
A solution that I came up with is as follows.
HTML:
CSS:
This stops the text from jumping around when the content is replaced.
Javascript:
I purposely didn’t use jquery as I’m planning on using this in a greasemonkey script and loading it on every page would slow things down (I think?). I had it working with it automatically changing on selection by binding mousemove after mousedown fired but it ended up being very slow so I decided it was best to focus on my goal of changing what was copied.
About the usage of non standard attributes, I’ve never found this to be a problem? I’m using title so that people can see the alternative format without copying it and data because it seemed logical.