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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:14:44+00:00 2026-05-30T05:14:44+00:00

my code is: <!DOCTYPE html> <html> <head> <title>Demo</title> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> <style

  • 0

my code is:

<!DOCTYPE html>
<html>
<head>
    <title>Demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css">
        p{
            border:1px solid #CCC;
            margin:5px;
            padding:5px;
        }
    </style>
    <script type="text/javascript">
        window.onload = changeColor;
        function changeColor() {
            for(var i =0; i < document.getElementById("main").getElementsByTagName("p").length; i++) {
                var obj = document.getElementById("main").getElementsByTagName("p")[i];
                if (window.addEventListener) {
                    obj.addEventListener('mousemove', function () {
                        this.style.backgroundColor ="#EEE";
                    }, false);
                    obj.addEventListener('mouseout', function () {
                        this.style.backgroundColor ="#FFF";
                    }, false);
                } else if (window.attachEvent) {
                    //for ie
                    obj.attachEvent('onmousemove', function () {
                        this.style.backgroundColor ="#EEE";
                    });
                    obj.attachEvent('onmouseout', function () {
                        this.style.backgroundColor ="#FFF";
                    });
                }
            }
        }
    </script>
</head>
<body>
    <div>
        <p>1</p>
        <div id="main">
            <p>2.1</p>
            <p>2.2</p>
            <p>2.3</p>
        </div>
    </div>
</body>
</html>

it work well in Chrome、FireFox and ie9,but can’t work in IE7/8

the error message is:Unable to set the property value of the “backgroundColor”: the object is null or undefined

what’s rong with me?

  • 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-30T05:14:46+00:00Added an answer on May 30, 2026 at 5:14 am

    When using attachEvent in IE, this is set to the window object, not to the object that the event happened on.

    In IE, the global variable window.event.srcElement will contain the target object for the event.

    You could code a work-around like this to make all the event handlers work the same:

    function hookEvent(event, obj, fn) {
        if (obj.addEventListener) {
            obj.addEventListener(event, fn, false);
        } else {
            obj.attachEvent("on" + event, function() {return(fn.call(obj, window.event));});
        }
    }
    

    This will make it so that this is set to the source object of the event and that the argument to the event handler is the event object.

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

Sidebar

Related Questions

My code: <!DOCTYPE html> <html> <head> <title>Demo</title> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> <style type=text/css>
my code is: <!DOCTYPE html> <html> <head> <title>Demo</title> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> <script
I downloaded sizzle.js from https://github.com/jquery/sizzle my code is: <!DOCTYPE html> <html> <head> <title>Demo</title> <meta
This is my code taken from http://jqueryui.com/demos/draggable/ <!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8>
Code: <html xmlns=http://www.w3.org/1999/xhtml> <head> <title>Unusual Array Lengths!</title> <script type=text/javascript> var arrayList = new Array();
I have this code: <!DOCTYPE html> <html> <head> <title>@ViewBag.Title</title> <link href=@Url.Content(~/Content/Site.css) rel=stylesheet type=text/css />
This is my code: <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd> <html> <head>
HTML : <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd> <html> <head> <meta name=generator
this is my google-map code: <!DOCTYPE html PUBLIC -//WAPFORUM//DTD XHTML Mobile 1.0//EN http://www.wapforum.org/DTD/xhtml-mobile10.dtd> <html
First off here is the code! <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>

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.