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 666441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:49:09+00:00 2026-05-13T23:49:09+00:00

Does anyone have any suggestions on how to edit an <a href=”> link in

  • 0

Does anyone have any suggestions on how to edit an <a href=''> link in a contentEditable div?

It would be ideal once the link is either clicked with mouse, or the cursor hits the link, that the a small prompt would pop up and allow the user to change the href property of the link.

The prompt isn’t the issue, but how is it possible to detect the link has been either clicked or that the cursor has arrived at the link?

onfocus doesn’t seem to work in a contentEditable div on Firefox & Safari.

Any ideas?

  • 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. Editorial Team
    Editorial Team
    2026-05-13T23:49:09+00:00Added an answer on May 13, 2026 at 11:49 pm

    I’m pretty sure this is what you were looking for, however I used jQuery just to make the concept a little easier to mock. jsbin preview available, so go look at it. If anyone is able to convert this to pure JS for the sake of the answer, I have made it a community wiki.

    It works by binding to the keyup/click events on the editable div, then checking for the node that the users caret is being placed at using window.getSelection() for the Standards, or document.selection for those IE people. The rest of the code handles popping/handling the edits.

    jQuery methods:

    function getSelectionStartNode(){
      var node,selection;
      if (window.getSelection) { // FF3.6, Safari4, Chrome5 (DOM Standards)
        selection = getSelection();
        node = selection.anchorNode;
      }
      if (!node && document.selection) { // IE
        selection = document.selection
        var range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange();
        node = range.commonAncestorContainer ? range.commonAncestorContainer :
               range.parentElement ? range.parentElement() : range.item(0);
      }
      if (node) {
        return (node.nodeName == "#text" ? node.parentNode : node);
      }
    }
    
    $(function() {
        $("#editLink").hide();
        $("#myEditable").bind('keyup click', function(e) {
            var $node = $(getSelectionStartNode());
            if ($node.is('a')) {
              $("#editLink").css({
                top: $node.offset().top - $('#editLink').height() - 5,
                left: $node.offset().left
              }).show().data('node', $node);
              $("#linktext").val($node.text());
              $("#linkhref").val($node.attr('href'));
              $("#linkpreview").attr('href', $node.attr('href'));
            } else {
              $("#editLink").hide();
            }
        });
        $("#linktext").bind('keyup change', function() {
          var $node = $("#editLink").data('node');
          $node.text($(this).val());
        });
        $("#linkhref").bind('keyup change', function() {
          var $node = $("#editLink").data('node');
          $node.attr('href', $(this).val());
          $node.and('#linkpreview').attr('href',$(this).val());
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have any suggestions on how to mentor a junior programmer ? If
Does anyone have any suggestions (or a regular expression) for parsing the HTTP Accept
Does anyone have any suggestions for a good approach to finding all the CPAN
Does anyone have any suggestions as to how I can clean the body of
Does anyone have any suggestions for creating meta tables in a database? These tables
Does anyone have any suggestions as to how to version an iphone application aside
Does anyone have any practical suggestions about how to manage feature creep in GUIs?
Does anyone have any good suggestions for creating a Pipe object in Java which
Does anyone have any suggestions for a good way to call R from S-Plus?
Does anyone have any recommendations of tools that can be of assistance with moving

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.