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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:44:05+00:00 2026-06-14T00:44:05+00:00

Possible Duplicate: Javascript IE Event I’m having a problem with IE8 executing my script.

  • 0

Possible Duplicate:
Javascript IE Event

I’m having a problem with IE8 executing my script. All other browsers are fine. The actual error is: ‘tagName is null or not an object’. I realize that my script is probably not the best, and could use work, but I really need it to work in IE8. The script is wrapped in a document.ready jQuery function, and my jquery version is 1.5.2. I have a feelings that the main problem has to do with var target = ev.target; but Im not sure.

The part of the script in question is:

var hrNav = document.getElementById('hrNavListen');
    var hrNav2 = document.getElementById('hrNavListenTwo');
    var startButton = document.getElementById('startButton');

    //Check to see if the user is on an iPad or iPhone
    var isiPad = (navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i)) != null;

    //If the user is on an iphone or ipad, use the touchstart event listener rather than click. Use click otherwise, or use onclick for IE users.
    if (isiPad == true) {
        hrNav.addEventListener('touchstart', highlight);
    } else {
        if(hrNav.addEventListener){  
            hrNav.addEventListener('click', highlight); 
            } else {  
                hrNav.attachEvent('on'+'click', highlight);
        }
    }
/* MAIN FUNCTION TO HIGHLIGHT THE CORRECT ITEM, AS WELL AS FILL IN CORRECT DATA */
    function highlight(ev) {

        var target = ev.target;

        //Function to set the dataSection variable to the appropriate string so that the correct section is loaded
        function switchContent(var1,var2,var3,var4,var5,var6,var7,var8,var9,var10,var11,var12,var13,var14,var15,var16,var17,var18) {
            switch (target.getAttribute('data-section')) {
                case var1:
                    var dataSection = 'hrPortalMain';
                    var btn = false;
                    break;
                case var2:
                    var dataSection = 'handbookMain';
                    var btn = true;
                    break;
                case var3:
                    var dataSection = 'handbookSection1';
                    var btn = true;
                    break;
                case var4:
                    var dataSection = 'handbookSection2';
                    var btn = true;
                    break;
                case var5:
                    var dataSection = 'handbookSection3';
                    var btn = true;
                    break;
                case var6:
                    var dataSection = 'handbookSection4';
                    var btn = true;
                    break;
                case var7:
                    var dataSection = 'handbookSection5';
                    var btn = true;
                    break;
                case var8:
                    var dataSection = 'handbookSection6';
                    var btn = true;
                    break;
                case var9:
                    var dataSection = 'handbookSection7';
                    var btn = true;
                    break;
                case var10:
                    var dataSection = 'handbookSection8';
                    var btn = true;
                    break;
                case var11:
                    var dataSection = 'handbookSection9';
                    var btn = true;
                    break;
                case var12:
                    var dataSection = 'handbookSection10';
                    var btn = true;
                    break;
                case var13:
                    var dataSection = 'handbookSection11';
                    var btn = true;
                    break;
                case var14:
                    var dataSection = 'antiDiscrimination';
                    var btn = true;
                    break;
                case var15:
                    var dataSection = 'substanceAbuse';
                    var btn = true;
                    break;
                case var16:
                    var dataSection = 'disclosureRelease';
                    var btn = true;
                    break;
                case var17:
                    var dataSection = 'emergencyContact';
                    var btn = true;
                    break;
                case var18:
                    var dataSection = 'submitForms';
                    var btn = true;
                    break;
            }/* /end switch */

            //Use jQuery AJAX to load the appropriate html
            $.ajax({
                url: "views/"+dataSection+".php",
                cache: false,
                dataType: "html"
            }).done(function( html ) { 
                $("#hrContent").html(html);
            });

            return dataSection;
        }

        if (target.nodeName === 'LI') {

            $("li").removeClass("navActive");
            $("span").removeClass("navActiveText");
            $("#hrarrow").remove();
            $(".navBodyText").css('margin-left','30px');
            $("#navMain,#navMOCForms,#navHandbookMain,#navGeneralPolicyMain,#navBenefitsMain,#navTaxMain").css('margin-left','0px');

            target.innerHTML += '<img src="img/hrarrow.png" id="hrarrow"/>';
            target.className += ' navActive';
            childSpan = target.firstChild;
            childSpan.style.marginLeft = '0';
            childSpan.className += ' navActiveText';
            childSpan.firstChild.className += ' navActiveText';

            switch (target.firstChild.id) {
                case 'navMain':
                    $("#navMain").css('margin-left','-30px');
                    break;
                case 'navMOCForms':
                    $("#navMOCForms").css('margin-left','-30px');
                    break;
                case 'navHandbookMain':
                    $("#navHandbookMain").css('margin-left','-30px');
                    break;
                case 'navGeneralPolicyMain':
                    $("#navGeneralPolicyMain").css('margin-left','-30px');
                    break;
                case 'navBenefitsMain':
                    $("#navBenefitsMain").css('margin-left','-30px');
                    break;
                case 'navTaxMain':
                    $("#navTaxMain").css('margin-left','-30px');
                    break;
            }/* /end switch */


            //Determine which content to load depending on the data-* HTML attribute of each LI elements
switchContent('hrPortalMain','handbookMain','handbookSection1','handbookSection2','handbookSection3','handbookSection4','handbookSection5','handbookSection6','handbookSection7','handbookSection8','handbookSection9','handbookSection10','handbookSection11','antiDiscrimination','substanceAbuse','disclosureRelease','emergencyContact','submitForms');

        }/* /endif */

        if (target.nodeName === 'SPAN') {

            $("li").removeClass("navActive");
            $("span").removeClass("navActiveText");
            $("#hrarrow").remove();
            $(".navBodyText").css('margin-left','30px');
            $("#navMain,#navMOCForms,#navHandbookMain,#navGeneralPolicyMain,#navBenefitsMain,#navTaxMain").css('margin-left','0px');

            target.className += ' navActiveText';
            parent = target.parentNode;

            if (parent.tagName === 'SPAN') {
                parent.parentNode.className += ' navActive';
                parent.className += ' navActiveText';
                parent.parentNode.innerHTML += '<img src="img/hrarrow.png" id="hrarrow"/>';
                $(".navActiveText").css('margin-left','0px');
            } else if(parent.tagName === 'LI') {
                parent.className += ' navActive';
                target.firstChild.className += ' navActiveText';
                parent.innerHTML += '<img src="img/hrarrow.png" id="hrarrow"/>';
                $(".navActiveText").css('margin-left','0px');
            }/* /endif */

            switch (target.id) {
                case 'navMain':
                    $("#navMain").css('margin-left','-30px');
                    break;
                case 'navMOCForms':
                    $("#navMOCForms").css('margin-left','-30px');
                    break;
                case 'navHandbookMain':
                    $("#navHandbookMain").css('margin-left','-30px');
                    break;
                case 'navGeneralPolicyMain':
                    $("#navGeneralPolicyMain").css('margin-left','-30px');
                    break;
                case 'navBenefitsMain':
                    $("#navBenefitsMain").css('margin-left','-30px');
                    break;
                case 'navTaxMain':
                    $("#navTaxMain").css('margin-left','-30px');
                    break;
            }/* /end switch */

            //Determine which content to load depending on the data-* HTML attribute of each LI elements
switchContent('hrPortalMain','handbookMain','handbookSection1','handbookSection2','handbookSection3','handbookSection4','handbookSection5','handbookSection6','handbookSection7','handbookSection8','handbookSection9','handbookSection10','handbookSection11','antiDiscrimination','substanceAbuse','disclosureRelease','emergencyContact','submitForms','employeeBenefitsPackage','flexSpending','dentalEnrollment','groupEnrollment','w4','i9','directDeposit','holidayPayroll','medOneForms','generalPolicy','benefitsMain','compensationMain');

        }/* /endif */

    }/* /end highlight function */
  • 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-06-14T00:44:06+00:00Added an answer on June 14, 2026 at 12:44 am

    IE8 doesn’t pass an instance of the event object to the handler, you’ll have to get it from the global object:

    ev = ev || window.event;
    

    It doesn’t share all of the properties and methods, either, including target:

    var target = ev.target || ev.srcElement;
    

    here’s a good site that explains the differences between MS’s take on events, and the W3C approach, and all of the headaches that this brings with it…
    No ev.preventDefault() but ev.returnValue = false; or ev.cancelBubble = true; instead of ev.stopPropagation(); etc…

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

Sidebar

Related Questions

Possible Duplicate: Javascript Object.Watch for all browsers? I just read Mozilla's documentation for the
Possible Duplicate: Detecting support for a given JavaScript event? having a random HTMLElement el
Possible Duplicate: “On file dialog cancel” event in JavaScript Is there a listener for
Possible Duplicate: Javascript Closure Problem In the following code, TrueThis.aChoices[i]['CallBack'] is a function when
Possible Duplicate: DOM Mutation event in JQuery or vanilla Javascript I am using backbone.js
Possible Duplicate: The current element as its Event function param Would this work <script
Possible Duplicate: Making sure a web page is not cached, across all browsers I
Possible Duplicate: Javascript infamous Loop problem? With the for loop, it does nothing. Without
Possible Duplicate: In JavaScript can I make a “click” event fire programmatically for a
Possible Duplicate: Event handlers inside a Javascript loop - need a closure? I have

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.