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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:23:38+00:00 2026-05-31T07:23:38+00:00

I had a function in which I had to attach event on an element

  • 0

I had a function in which I had to attach event on an element newElement I checked the condition whether its IE or Firfox based on attachEvent property (works only in IE).

if ( typeof(newElement.attachEvent) != "undefined" )
{               
    newElement.attachEvent("onclick", deleteRow) ;  
    newElement.attachEvent("onclick", customDeleteScript) ;
}else
{   

    newElement.addEventListener("click", deleteRow, false) ;    
    newElement.addEventListener("click", customDeleteScript, false) ;               
} 

The required flow was deleteRow to execute first followed by customDeleteScript
It is working fine in Firefox/Chrome but the flow changes in IE customDeleteScript executes before deleteRow in IE. So I had to do as follows:

if ( typeof(newElement.attachEvent) != "undefined" )
{               
    newElement.attachEvent("onclick", customDeleteScript) ;
    newElement.attachEvent("onclick", deleteRow) ;  
}else
{   

    newElement.addEventListener("click", deleteRow, false) ;    
    newElement.addEventListener("click", customDeleteScript, false) ;               
} 

The question here lies is this property of IE or it is just a random hit and trial kind of scenario for IE always?

EDIT: What in case my function contains some parameters like this and others and I don’t know which function takes which parameters.

  • 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-31T07:23:39+00:00Added an answer on May 31, 2026 at 7:23 am

    If order is important, you should not use separate event handlers. Call both functions in the desired order from one event handler like this:

    function delete() {
        deleteRow();
        customDeleteScript();
    }
    
    if ( typeof(newElement.attachEvent) != "undefined" )
    {               
        newElement.attachEvent("onclick", delete) ;  
    }else
    {   
    
        newElement.addEventListener("click", delete, false) ;    
    } 
    

    FYI, a generic event handler function that you can reuse works like this:

    function addEvent(elem, event, fn) {
        if (elem.addEventListener) {
            elem.addEventListener(event, fn, false);
        } else {
            elem.attachEvent("on" + event, function() {
                // set the this pointer same as addEventListener when fn is called
                return(fn.apply(elem, arguments));   
            });
        }
    }
    

    Note, it’s better to check for addEventListener first so if both methods exist (like in IE9), your code will use the standard way.

    So, your code can work like this:

    addEvent(newElement, 'click', function() {
        deleteRow();
        customDeleteScript();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a function which is pulling all the dates from database against each
I had a function below which stores distances from two locations using google maps
I've had problem when trying write a function which has a default value when
I had to write a function which binary_print(outstream& outs,unsigned int a) but when i
In Drupal 6, my module had this next function which inserted a javascript to
I have the following function which works fine when tied to an onClick() event..
I've got a DLL which makes a call to SetDllDirectory() in its DllMain() function.
I had a function like this, that wasn't within a class: // Gets the
The old JS SDK had a function called FB.ensureInit. The new SDK does not
I recall reviewing someone else's PHP code once and he had a function or

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.