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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:51:58+00:00 2026-05-30T05:51:58+00:00

I’m working on a text editor. When the user double-clicks on a specific <div>

  • 0

I’m working on a text editor. When the user double-clicks on a specific <div>, the contentEditable property is set to true and some editor tools appear. Then, the user can choose between clicking on “save” and “escape”. If he escapes, I want to restore the previous data in this <div>. So I copy data on first double-click (temp['htmlTxt']) and then:

$('#esc').click(function() {
    var confEsc = confirm('---\n\nSouhaitez-vous quitter sans enregistrer vos modifications ?\n\n---');

    if(confEsc) { 

       //Do you know why that works :
       var id = document.getElementById(temp['myId']);
       id.innerHTML = temp['htmlTxt'];

       //and why that doesn't work ?
       $('#'+temp['myId']).html(temp['htmlTxt'])
    }
});

I don’t understand why it works fine with classic JavaScript and not with jQuery…

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

    Those 2 are practically identical. However jQuery does some pre-processing that might be getting in your way…

    jQuery Globals

    rnoInnerHtml = /<(?:script|style)/i;
    rtagName = /<([\w:]+)/;
    rleadingWhitespace = /^\s+/;
    rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi;
    wrapMap = {
        "option": [1, "<select multiple='multiple'>", "</select>"],
        "legend": [1, "<fieldset>", "</fieldset>"],
        "thead": [1, "<table>", "</table>"],
        "tr": [2, "<table><tbody>", "</tbody></table>"],
        "td": [3, "<table><tbody><tr>", "</tr></tbody></table>"],
        "col": [2, "<table><tbody></tbody><colgroup>", "</colgroup></table>"],
        "area": [1, "<map>", "</map>"],
        "_default": [0, "", ""],
        "optgroup": [1, "<select multiple='multiple'>", "</select>"],
        "caption": [1, "<table>", "</table>"],
        "colgroup": [1, "<table>", "</table>"],
        "tfoot": [1, "<table>", "</table>"],
        "tbody": [1, "<table>", "</table>"],
        "th": [3, "<table><tbody><tr>", "</tr></tbody></table>"]
    };
    

    .html(value) setter

    var elem = this[0] || {},
        i = 0,
        l = this.length;
    
    if (typeof value === "string" && !rnoInnerhtml.test(value) && 
        (jQuery.support.leadingWhitespace || !rleadingWhitespace.test(value)) && 
        !wrapMap[(rtagName.exec(value) || ["", ""])[1].toLowerCase()]) {
    
        value = value.replace(rxhtmlTag, "<$1></$2>");
    
        try {
            for (; i < l; i++) {
                // Remove element nodes and prevent memory leaks
                elem = this[i] || {};
                if (elem.nodeType === 1) {
                    jQuery.cleanData(elem.getElementsByTagName("*"));
                    elem.innerHTML = value;
                }
            }
    
            elem = 0;
    
            // If using innerHTML throws an exception, use the fallback method
        } catch(e) {}
    }
    
    if (elem) {
        this.empty().append(value);
    }
    

    that’s straight out of the current version for the setter on .html(string)

    so basically if you value (1) isn’t a string, (2) has a script tag, (3) your on a browser that doesn’t support leading white-space and you string isn’t trimmed, (4) you tag falls into the wrapMap special use cases OR (5) innerHTML fails for ANY other reason.. THEN you are essentially calling .empty().append(value) which is a whole different ball of wax… -ck

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in

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.