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

  • SEARCH
  • Home
  • 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 6692511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:52:34+00:00 2026-05-26T05:52:34+00:00

Jsfiddle: http://jsfiddle.net/qTEmc/1/ I need to associate events with the keypress event on links which

  • 0

Jsfiddle: http://jsfiddle.net/qTEmc/1/

I need to associate events with the keypress event on links which are added in the contenteditable.

If you try typing in the contenteditable area in the linked jfiddle, you’ll see it creates a link and you can type within it. I fyou press return, you go to a newline. What I want is for pressing return in the new link to trigger a function. For the sake of progress, I’m just trying to get it to return an alert at the moment.

Does anyone know a reliable way to do this?

  • 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-26T05:52:35+00:00Added an answer on May 26, 2026 at 5:52 am

    You won’t be able to detect key events within the links themselves because they don’t fire key events. Instead, you’ll need to adapt your existing keypress handler for the contenteditable element to inspect the selection to see if it lies within a link. Here’s a function to do that. I’ve also updated your demo.

    function selectionInsideLink() {
        var node = null, sel;
    
        // Get the selection container node
        if (window.getSelection) {
            sel = window.getSelection();
            if (sel.rangeCount) {
                node = sel.getRangeAt(0).commonAncestorContainer;
            }
        } else if (document.selection) {
            sel = document.selection;
            if (sel.type != "Control") {
                node = sel.createRange().parentElement();
            }
        }
    
        // Check if the node is or is contained inside a link
        while (node) {
            if (node.nodeType == 1 && node.tagName.toLowerCase() == "a") {
                return true;
            }
            node = node.parentNode;
        }
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

jsfiddle: http://jsfiddle.net/DQGMb/ I have JQuery UI Tabs which I would like to stretch all
var x = window.Something; alert(window.x) when i try this code in jsfiddle http://jsfiddle.net/XJEGU/ ,
In this JsFiddle : http://jsfiddle.net/maxl/mCXND/ (copied and modified from http://jsfiddle.net/ud3323/XMgwV/ ) I try to
In this JSFiddle http://jsfiddle.net/9UMRk/ A div has a margin-top of 50%. Which I would
In this JSFiddle http://jsfiddle.net/JQ6qF/ have I striped down the problem. Try click on Save
jsfiddle: http://jsfiddle.net/MFUw3/5/ jQuery: function showDiv() { if ($(window).scrollTop() > 610) { $(.a).css({position: fixed, top:
JSFiddle: http://jsfiddle.net/dvF5d/2/ <input type=radio id=rad1 name=rad/><label for=rad1>rad1</label><br/> <input type=checkbox id=chk1/><label for=chk1>chk1</label><br/> <input type=radio id=rad2
Have a look at this jsfiddle: http://jsfiddle.net/Dh96F/1/ The Expand button will animate the widening
Here is the link to the jsfiddle: http://jsfiddle.net/d3xMZ/ when I hover, it does exactly
I have the following code that is working fine in jsfiddle - http://jsfiddle.net/darkajax/FHZBy/ I've

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.