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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:52:16+00:00 2026-05-13T05:52:16+00:00

I want to change the method DomElement.appendChild() to work differently when applied on an

  • 0

I want to change the method DomElement.appendChild() to work differently when applied on an Object that I have created:

// using MooTools;
var domElement = new Class({...});

var MyObject = new domElement(...);

$(document).appendChild(MyObject); // Error

// I want to add to (extend) appendChild, to do something specific, when:
alert(MyObject instanceof domElement); // true

I could do this by modifying the mootools.js, but I want to avoid this at all costs, because I am certain one day, some other developer will overwrite the js file with an updated version, and I will be imprisoned for murder.

Please, keep me out of jail!

  • 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-13T05:52:16+00:00Added an answer on May 13, 2026 at 5:52 am

    I dont know about MooTools, but there is a simple way in native JS to do this..

        var orgAppendChild = document.appendChild;  
        document.appendChild = localAppendHandler;
    
    
        var domElement = new Class({...});
        var MyObject = new domElement(...);
        // document.appendChild(MyObject);
    
         var ss = document.createElement('tr'); 
    document.appendChild (ss);
    
    
        function localAppendHandler(MyObject)
        {
         if (MyObject instanceof domElement)
            UrCustomRoutine(MyObject )
            else
                orgAppendChild(MyObject);
    
    
        }
    
        function UrCustomRoutine(MyObject ){
        //your custom routine
        }
    

    Hope this helps

    Update:
    From your further explanation (handling appendChild of any DOM element), i understand that there is no generic way of defining local hanlders to trap the event.

    But there is a workaround (this is very ugly i know). Means you have to define a LocalHandler for the DOM element before you are goin to use the appendChild .

    Before doing this
    document.getElementByID(‘divTarget’).appendChild()

    you have to reassign the localhandler to the element you need to access

        orgAppendChild = document.getElementById('divTarget').appendChild;  
        document.getElementById('divTarget').appendChild = localAppendHandler;
        var sss = document.createElement('table'); 
        document.getElementById('divTarget').appendChild(sss);
    

    Another Alternative:
    If you wanted to keep it simple, i suggest this alternate way. Create AppendChild local method which accepts object and the node name as param.

        function AppendChild(MyObject ,Node)
        {
               if (MyObject instanceof domElement)
                   //your custom routine
               else if (Node=="" && (MyObject instanceof domElement==false))
                   document.appendChild(MyObject);
               else if (Node!="" && (MyObject instanceof domElement==false))
                   eval( "document.getElementById('" + Node + "').appendChild(MyObject);");
    
    
        }
    

    And

    1. If you wanted to append DOM element to document

       AppendChild(DOMelement,"")
      
    2. If you wanted to append DOM element inside other
      container

       AppendChild(DOMelement,"divTarget")
      
    3. If you wanted to process your custom object

       AppendChild(customObject,"")
      

    this is the best way to do this.

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

Sidebar

Related Questions

I have created several UI elements in the viewDidLoad method. I want to change
I'm trying to create an .on() method using events-map. I want to change this:
I have this Dispose method I want to change. (Yeah I should check every
My requirement is that I want an object (tee) to update if there have
I want to change the font I am using in a CEikLabel on S60
I have a vc++ method that uses fprintf to write values to a file
Trying to change the __unicode__ method on an instance after it's created produces different
I want to customize a object's behavior before the object is created. I think
I want to change the redirect on a create method, but I don't want
I want to change an image of an UIImageView from the applicationDidFinishLaunching method of

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.