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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:36:04+00:00 2026-05-25T22:36:04+00:00

I dynamically create DOM elements based upon the user input using this code (Example

  • 0

I dynamically create DOM elements based upon the user input using this code (Example 1). I also use php/xhtml to create the same elements on a reload (Example 2).

Problem I’m seeing is that my image onerror event only works for the reloaded version. Here I use traditional inline event registration to i_bm_err and it works.

However for the javascript version, the onerorr callback method does not fire.

My questions: Do I need to add an event Listener? If so, what is the event listener’s type? I have tried adding event listeners of type “error” and “onerror”, but this did not work. This makes me think that maybe adding and evernt listener is not the issue.

Example 1

function o3(a)  
  {
  return document.createElement(a);
  }

  var b=o3('a');
    b.innerHTML=c[1].value;
    b.href=c[2].value;
    b.name="a1";
    b.className="b";
    b.target="_blank";
  var e=o3('img');
    e.className="c";
    e.name="bo_im";
    e.src=b.href+'favicon.ico';
    e.onerror=function(e){e.src='http://www.archemarks.com/favicon1.ico';};

Example 2

PHP / XHTML

  function bookmarks()
    {
    $email = $_SESSION['email'];
    $query_return = database::query("SELECT * FROM bo  WHERE email='$email' ORDER BY name ASC");
    while ($ass_array = mysqli_fetch_assoc($query_return))
      {
      $fav=$this->fav($ass_array['url']);
      echo "<img name=\"bo_im\" class=\"c\" src=\"$fav\"/ onerror=\"i_bm_err(this)\"><a target=\"_blank\" name = \"a1\" class = \"b\" href = \"$ass_array[url]\">$ass_array[name]</a>";
      }
    }

Javascript

function i_bm_err(a)
  {
  a.src='http://www.archemarks.com/favicon1.ico';
  }

Research:

MDN – element.addEventListener

In the example above, the value of this within modifyText() when
called from the click event is a reference to the table ‘t’. This is
in contrast to the behavior that occurs if the handler is added in the
HTML source:

  • 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-25T22:36:04+00:00Added an answer on May 25, 2026 at 10:36 pm

    As @Paul Grime mentioned, you need to attach all your events (error, load etc) prior to setting the src attribute.

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

Sidebar

Related Questions

I'm creating DOM elements dynamically (more specifically, using jQuery to create a DIV containing
I'm using scriptaculous Builder to generate some DOM elements dynamically, and one of them
Dear experts, I was trying to dynamically generate DOM elements using JS. I read
I can use this jQuery code to dynamically change the RSS link in the
I am trying to dynamically create a Bitmap Image using byte array using following
I have a form with dynamically created input fields - upon submitting it I
I have a page that uses jQuery to create a number of <input> DOM
In my application, I sometimes have to create elements dynamically, so I create them
i'm using java script to dynamically create an element and populate it with content.
Is it possible to dynamically create and modify images on a per pixel level

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.