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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:47:47+00:00 2026-05-25T00:47:47+00:00

Basically I want user to click on any .editable item, which makes an input

  • 0

Basically I want user to click on any .editable item, which makes an input appear, copy its styles, and then if they click anywhere else, I want the input to disappear and the changes to save. I’m having difficulty making this work. I’ve seen a solution using event.stopPropagation, but I don’t see how to include it the way I have my code structured:

$(function() {
    var editObj = 0;
    var editing = false;   

    $("html").not(editObj).click(function(){
         if (editing){
                $(editObj).removeAttr("style");
                $("#textEdit").hide();
                alert("save changes");
            }
    });    


    $(".editable").not("video, img, textarea")
        .click(function(event) {

            editObj = this;
            editing = true;

            $("#textEdit")
                .copyCSS(this)
                .offset($(this).offset())
                .css("display", "block")
                .val($(this).text())
                .select();

            $(this).css("color", "transparent");


    });
}

copyCSS function from here

I need to distinguish between clicks on the editable object, and clicks away from it, even if that click is onto a different editable object (in which case it should call 2 events).

  • 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-25T00:47:47+00:00Added an answer on May 25, 2026 at 12:47 am

    Try this:

    $('body').click(function(event) {
        var parents = $(event.target).parents().andSelf();
        if (parents.filter(function(i,elem) { return $(elem).is('#textEdit'); }).length == 0) {
            // click was not on #textEdit or any of its childs
        }
    });
    
    $(".editable").not("video, img, textarea")
            .click(function(event) {
    
        // you need to add this, else the event will propagate to the body and close
        e.preventDefault();
    

    http://jsfiddle.net/dDFNM/1/

    This works by checking if the clicked element, or any of its parents, is #textEdit.

    The event.stopPropagation solution can be implemented this way:

    // any click event triggered on #textEdit or any of its childs
    // will not propagate to the body
    
    $("#textEdit").click(function(event) {
        event.stopPropagation();
    });
    
    // any click event that propagates to the body will close the #textEdit
    
    $('body').click(function(event) {
        if (editing) {
            $("#textEdit").hide();
        }
    });
    

    http://jsfiddle.net/dDFNM/2/

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

Sidebar

Related Questions

I want to write a rule in prolog, which basically says If a user
Basically I want to check what url the user is on and compare it
Basically, I do not want the user to enter '0' (zero) as the first
Basically what I want to do is allow a user to type in a
I have a bit of a problem with user controls. Basically what I want
I want to make a site where there user can basically navigate the web
Basically I will tell you what I want to do. 1: If a user
Basically I've got a huge table, which gets even bigger as user scrolls down
Basically I have an anchor element, <a href='bla..'>link</a> On click, I first want to
I want to have a JTextField (or another text-like input which supports focus and

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.