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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:06:09+00:00 2026-05-11T12:06:09+00:00

I use code like this to dynamically create some link-based controls: <script type=text/javascript> function

  • 0

I use code like this to dynamically create some link-based controls:

<script type='text/javascript'>     function BuildControls (id, ...)     {           var div = document.getElementById (id);           /* some stuff with var sp=document.createElement('span'); */         var a = document.createElement ('a');         a.innerHTML = on ? 'Cancel' : captions_do[i];         a.className = class_do;         a.style.display = on2 ? '' : 'none';         a.id = 'iAccept'+id+'_'+i+'Control';         div.appendChild (sp);         div.innerHTML+='<br />';         div.appendChild (a);         a.onclick = function () {alert ('wtf')};         div.innerHTML+='<br />';     } </script> ... <div id='someid'></div>   <script type='text/javascript'>       BuildControls ('someid', ...); </script> 

So when I click on the link, it does nothing. If I call a.onclick() explicitly, it works. What is wrong?

  • 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. 2026-05-11T12:06:10+00:00Added an answer on May 11, 2026 at 12:06 pm

    div.innerHTML+='<br />’;

    That is syntactical sugar for:

    div.innerHTML= div.innerHTML+'<br />’;

    Which makes it clearer what is happening: you just serialised the entire contents of the div to HTML, added a tiny string, and parsed the results back into HTML. Even if it worked flawlessly, that’d be really inefficient.

    When you serialise an element, you lose any non-attribute-based information attached to it, including JavaScript properties, event handlers and listeners. Say goodbye to your onclick.

    Never use “innerHTML+=”. It is always a mistake.

    An alternative is to set innerHTML on a standalone div not attached to the document, then append its childNodes one-by-one to the element where you really want it.

    But for something this simple, you should just be using the standard DOM methods:

    div.appendChild(document.createElement('br')); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 117k
  • Answers 117k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer grep's -A 1 option will give you one line after;… May 11, 2026 at 10:45 pm
  • Editorial Team
    Editorial Team added an answer Option 2 makes more sense to me. I don't like… May 11, 2026 at 10:45 pm
  • Editorial Team
    Editorial Team added an answer Well, the only they might differ is in the HTTP… May 11, 2026 at 10:45 pm

Related Questions

I have a test program called ftest. It loads .so files that contain tests
I have looked all of the place for this and I can't seem to
This is a simplified version of the original problem. I have a class called
Not sure if this is possible or if I'm expressing correctly what I'm looking

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.