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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:34:47+00:00 2026-05-20T11:34:47+00:00

I want to dynamically add some preconfigured HTML-Elements in use of a ‘click’-event with

  • 0

I want to dynamically add some preconfigured HTML-Elements in use of a ‘click’-event with mootools.

So I can make it work with my basic knowledge, although it isn´t very nifty. I coded this so far…

This is my preconfigured element, with some text, a classname and some event, cause i wanna have events already added, when it´s inserted into my container:

        var label = new Element('label', {
            'text': 'Label',
            'class': 'label',
            'events': {
                'click': function(el){
                    alert('click');
                }
            }
        });

Here is my function, which adds the label-Element:

        function addText(){
            $('fb-buildit').addEvent('click', function(){                   
           row.adopt(label, textinput, deletebtn);
            $('the-form').adopt(row.clone());
            row.empty();

    /*
    label.clone().inject($('the-form'));
    textinput.inject($('the-form'));
    deletebtn.inject($('the-form'));
    */

            });
        }

The second part which uses inject also works, but there, my click-Event, which fires the “alert(‘click’)” works too. The method with adopt doesn´t add any event to my label Object, when its inserted in the dom.

Can anyone help me with this. I just wanna know why adobt ignores my “events” settings and inject doesn´t.

Thanks in advance.

(sorry for my english ^^)

  • 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-20T11:34:47+00:00Added an answer on May 20, 2026 at 11:34 am

    you go label.clone().inject but row.adopt(label) and not row.adopt(label.clone()) –

    either way. .clone() does not cloneEvents for you – you need to do that manually.

    var myclone = label.clone();
    myclone.cloneEvents(label);
    row.adopt(label);
    

    this is how it will work

    as for why that is, events are stored in the Element storage – which is unique per element. mootools assigns a uid to each element, eg, label = 1, label.clone() -> 2, label.clone() -> 3 etc.

    this goes to Storage[1] = { events: ... } and so forth. cloning an element makes for a new element.uid so events don’t work unless you implicitly use .cloneEvents()

    you are sometimes not doing .clone() which works because it takes the ORIGINAL element along with its storage and events.

    suggestion consider looking into event delegation. you could do

    formElement.addEvent("click:relay(label.myLabel)", function(e, el) {
        alert("hi from "+ el.uid);
    });
    

    this means no matter how many new elements you add, as long as they are of type label and class myLabel and children of formElement, the click will always work as the event bubbles to the parent.

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

Sidebar

Related Questions

I want to dynamically add some columns (and remove others) from an html table.
Suppose you want to dynamically add to a HTML menu, where the menu HTML
HI.. i want to add elements dynamically to listview in QT for symbian OS,
I want to dynamically create a 1-row grid and add some TextBlocks to it,
I'm making some code to dynamically add more rows to a table on click.
I want to dynamically add some widgets like so: LinearLayout llay = new LinearLayout(this);
I want to add div dynamically for particular html Here, i will give you
I'm using jQuery.append() to add some elements dynamically. Is there any way to get
I have some code that dynamically add button to StackPanel. I want to do
I'm building a .NET application where I want to dynamically add an email address

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.