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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:45:31+00:00 2026-05-26T02:45:31+00:00

Adding new html string into the page: document.getElementById(‘container’).innerHTML = ‘<div id=child></div>’; Is there an

  • 0

Adding new html string into the page:

document.getElementById('container').innerHTML = '<div id="child"></div>';

Is there an event that let me know when child element is in the document?

I have a function, which return some html codeas a string. And when this html will be added in the document, I need to execute javascript function. I’ve tried to use inline onload event

document.getElementById('container').innerHTML = '<div id="child" onload="console.log(\'ready!\');"></div>';

but it does not seem to work.

UPDATE:
Probably, I should provide more details about the situation. I have a library function

myLibrary.getHtml()

In old version, users just call this function and append the result into the document:

document.getElementById('container').innerHTML = myLibrary.getHtml();

In new version, the result is not a plain html. Now users can interact with it after they append it in the document. So after they append html into the document, I need to go through the result DOM and attach event handlers, hide some elements and other things. That is why, I need to know when they add it in the document and execute a javascript function, which turn plain html into fancy interactive widget.

  • 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-26T02:45:31+00:00Added an answer on May 26, 2026 at 2:45 am

    Solved by myself this way:

    myLibrary.getHtml = function() {
        var html;
        ...
        var funcName = 'initWidget' + ((Math.random() * 100000) | 0);
        var self = this;
        window[funcName] = function() { self._initWidget(); };
        return html + '<img src="fake-proto://img" onerror="' + funcName + '()"';
    }
    

    The idea behind the code is that I specify incorrect url for the src attribute of the img tag and the image triggers error event and call my function. Quite simple 🙂

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

Sidebar

Related Questions

How do I stick HTML formatting into a String object in C#? Here's what
I'm adding new element through html() function of jQuery. Then I want to handel
When adding new properties to classes, I find myself typing the same things over
I have situation where I need to change the order of the columns/adding new
Clojure structs can be arbitrarily extended, adding new fields. Is it possible to extend
I have a TreeView control on a form. I am dynamically adding new TreeNodes
I'm adding a new field to a list and view. To add the field
I'm currently adding some new extended classes to this code: foreach (BaseType b in
I'm adding a new Row to a BindingSource that is Bound to a DataGridView
I'm updating a program and adding a new table to the database. The program

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.