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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:36:03+00:00 2026-05-23T21:36:03+00:00

I saw a lot of posts about this pattern, but still don’t understand why

  • 0

I saw a lot of posts about this pattern, but still don’t understand why it’s not work in mine code. Using Chromium on Ubuntu 10.04.

function showDescription(){
    var description = document.createElement('div'),
    eventTarget = window.event.target,
    newHTML = description.innerHTML;

    description.id = 'description';

    switch(eventTarget.getAttribute('data-par')){
        case 'links': newHTML = newHTML.replace(newHTML, 'links')
            break;
        case 'images': newHTML = newHTML.replace(newHTML, 'images')
            break;
    };
    console.log(newHTML);
    parentElement.insertBefore(description, parentElement.firstChild.nextSibling);
};

    var descParLi = descPars.getElementsByTagName('li');
    for (var i = 0; i < descParLi.length; i++){
    descParLi[i].addEventListener("click", showDescription);
};

This code contained in other function. Strangely, in console I see value of newHTML, but in html have no changes, that’s a problem. What is wrong? How to fix?

  • 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-23T21:36:04+00:00Added an answer on May 23, 2026 at 9:36 pm

    You aren’t adding the content to the actual div you created.

    switch(eventTarget.getAttribute('data-par')){
        case 'links': description.innerHTML = 'links'
            break;
        case 'images': description.innerHTML = 'images'
            break;
    };
    
    console.log( description.innerHTML );
    

    There’s no point in doing:

    newHTML = description.innerHTML
    

    …or:

    newHTML.replace(newHTML, 'images')
    

    …because description is a brand new element, so there isn’t any innerHTML content yet.


    EDIT: I used div instead of description for the variable name above. It should use description instead:

    description.innerHTML = 'xxxxx'
    

    Fixed.

    Here’s the entire function:

    var i = 0;
    
    function showDescription(){
        var description = document.createElement('div'),
        eventTarget = window.event.target;
    
        description.id = 'description' + i;  // <-- make the ID unique
    
        i++;  // <-- increment "i" so that it's different on the next run
    
        switch(eventTarget.getAttribute('data-par')){
            case 'links': description.innerHTML = 'links'
                break;
            case 'images': description.innerHTML = 'images'
                break;
        };
        console.log( description.innerHTML );
    
          // v----What is parentElement supposed to reference?
        parentElement.insertBefore(description, parentElement.firstChild.nextSibling);
    }
    

    Notice I added an incrementing i so that your ID will be unique each time.

    This won’t be necessary if you’re removing the element before another one is shown.

    Also, you have a parentElement. I don’t know what that’s supposed to reference.

    If it is some appropriate variable not shown, then you’re fine, but if it should be a reference to the parent of the target, then you should do this instead:

    target.parentNode.insertBefore(description, target.parentNode.firstChild.nextSibling);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw many threads with this tittle, but no one really speak about reuse
I saw lot of posts in StackOverflow and elsewhere talking about concrete implementation. While
I saw a lot of examples of CopyStream implementation but I have question about
I've searched a lot but could not solve this problem. I am generating PDF
I have saw a lot of them, but all they look not accelerated and
I saw a lot of topics about powershell + waiting for process ending, but
I look up a lot through this problem while i saw many post abt
I saw in a lot of AjaxControlToolkit.resources.dll for different languages, even mine (Russian) in
I have read a lot about soft deletes and archive and saw all the
I saw some code when studying the open source project: here . But I

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.