Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 171507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:00:00+00:00 2026-05-11T13:00:00+00:00

Is it possible to change the contents of elements when they, or a part

  • 0

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> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:00:00+00:00Added an answer on May 11, 2026 at 1:00 pm

    A solution that I came up with is as follows.

    HTML:

    <p>Semper mi vitae tellus <span class='date' title='19/03/09' data='19th of March'>19th of March</span> quis, augue.</p> 

    CSS:

    .date {     display:inline-block;     text-align:center; } 

    This stops the text from jumping around when the content is replaced.

    Javascript:

    var travel = function(node, noChildren){     if (node.firstChild && !noChildren) {         return node.firstChild;     }     if (node.nextSibling) {         return node.nextSibling;     }     return travel(node.parentNode, true); };  var onMouseDown = function(event){     var spans = document.getElementsByClassName(revertClass);     var i = spans.length;     while (i) {         i--;         spans[i].innerHTML = spans[i].getAttribute('data');         spans[i].className = window.baseClass;     }      var selection = window.getSelection();     if (selection.rangeCount && event.button === 2){         var n = selection.rangeCount;         var k = n;         do {             var i = k-n;             var range = selection.getRangeAt(i);              var element = range.startContainer;             var endContainer = range.endContainer;             do {                 if (element.className === window.baseClass){                     element.style.width = element.offsetWidth;                     element.innerHTML = element.title;                     element.className += ' ' + window.revertClass;                 }                 if (element == endContainer){                     break;                 }             }             while (element = travel(element));              var newRange = document.createRange();             newRange.setStart(range.startContainer, range.startOffset);             newRange.setEnd(range.endContainer, range.endOffset);              selection.removeRange(range);             selection.addRange(newRange);         }         while (--n);     } };  var onKeyDown = function(event){     //Ctrl + C     if (event.keyCode === 67 && event.ctrlKey){         event.button = 2;         onMouseDown(event);     }     //Tab to deselect     else if (event.keyCode === 9){         onMouseDown(event);     } };  window.baseClass = 'date'; window.revertClass = 'date_revert'; window.addEventListener ('mousedown', onMouseDown, false); window.addEventListener ('keydown', onKeyDown, false); 

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to change the color of View Results text in below ?
Possible Duplicate: Change the URL in the browser without loading the new page using
Possible Duplicate: Change icon on of an App in iOS 4 in run-time Is
Possible Duplicate: change layout and template in zend dynamically according to the device(android tab,iphone,ipad)
Is it possible to change C#'s built-in Vector3 struct to not use floating point
Is it possible to change object's value not directly? For example a = {x:
is it possible to change the Audience of an already existing Post in my
Is it possible to change only Y value of background position in CSS? background-position-y
Is it possible to change SQL in a z/OS mainframe COBOL application so that
Is it possible to change the size of an UITabBarItem? I'm not talking about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.