Target is null or not an object how to fix ie browser. It works good in firefox. Please help how to fix the challenging script error.

Dani AI

Generated

That IE message simply means your code is trying to use a property or method on null (or undefined). Common causes are: querying an element before the DOM exists, using event.target in older IE, or a wrong/missing element ID. Quick checklist before posting code: confirm the element ID is correct and unique, add guards (if (el) { ... }), and attach handlers only after the DOM is ready.

Cross‑browser event target (works in old IE and modern browsers):

function handler(e) {
  e = e || window.event;
  var target = e.target || e.srcElement;
  if (!target) return;
  // safe to use target here
}

Ensure the DOM is ready before accessing elements. Either place scripts just before </body> or use a DOM‑ready pattern:

function ready(fn) {
  if (document.readyState === 'complete' || document.readyState === 'interactive') {
    fn();
  } else if (document.addEventListener) {
    document.addEventListener('DOMContentLoaded', fn);
  } else {
    document.attachEvent('onreadystatechange', function() {
      if (document.readyState === 'complete') fn();
    });
  }
}

Debug tips: open IE Dev Tools (F12), set script debugging, and add debugger; or guarded logs (if (window.console) console.log(...)). Remember in IE8 and earlier console is undefined unless Dev Tools are open, so guard console calls. When replying, paste the exact script with the Code button as suggested so responders can see where null comes from. For more on event targets and DOM ready behavior see Event.target and DOMContentLoaded.

Recommended Answers

All 3 Replies

Without your script it's impossible to determine what the cause is.

how i paste the script code here

Use the "Code" button. You get a popup where you can paste your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.