Dojo - add event listener to dynamically created element

Christer

Hi I'm trying to add event listener to dynamically created "<a></a>" element, but with no success.

Here is the item/element:

var item = "<div class='item' id='" + id + "'>"
            + "<div class='cell ion-chevron-right'>"
            + "<span class='cell items'>" + text + "</span>"
            + "<a id='" + id + "_icon' class='mIcon ion-ios-close-outline' style='margin-left:-22px; font-size:18px;'></a>"
            + "</div>"
            + "<div class='cell'>" + price + "</div>"
            + "</div>";

            return item;
          }

And here I insert it into the HTML:

var addAccessorie = function(id, text, price){
            var m = id + "_accessorie";
            dojo.place(newAccesorieItem(m, text, price)
            ,"maintenance_accessorie"
            ,"after"); // before/after
          }

How can I add a CLICK event to the "<a>" in DOJO?

Himanshu

Use dojo/dom-construct to create the <a> element and then use dojo/on to bind the onclick event.

var aElement= domConstruct.toDom("<a id='" + id + "_icon' class='mIcon ion-ios-close-outline'
             style='margin-left:-22px; font-size:18px;'></a>");

on(aElement, 'click', function(){
    //Your click handler
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Add Event Listener for dynamically created particular element using jquery

From Dev

How to add event listener to element created dynamically within prototype?

From Dev

jquery - add event listener to dynamically created button

From Dev

Add event listener to dynamically created button

From Dev

Add data to dynamically created element and bind event

From Dev

jQuery - Add click event to a dynamically created element

From Java

Dynamically add event listener

From Dev

Event listener for dynamically created html

From Dev

Dynamically Created Element and event

From Dev

jQuery object-oriented created dom element and add event listener

From Dev

Dojo Event dynamically created events not handled

From Dev

Adding Event Listener to dynamically created divs

From Dev

Binding event to dynamically created element

From Dev

Event Binding on Dynamically Created Element

From Dev

How to attach an event listener to dynamically added widget content in Dojo toolkit

From Dev

How to add a function/event listener to an element created with ES6's template literals?

From Dev

Symfony2 add event listener dynamically

From Dev

dynamically add event listener for function with variable

From Dev

Add event listener to form element added by event listener

From Dev

jQuery Tooltip event not firing on dynamically created element

From Dev

Dynamically created element not firing click event

From Dev

jQuery event not triggering on dynamically created element

From Dev

jQuery Tooltip event not firing on dynamically created element

From Dev

Why does this dynamically created element not bound to an event?

From Dev

Dynamically created element not firing click event

From Dev

jquery listen to click event on dynamically created element

From Dev

Passing an argument to a event listener from dynamically created buttons

From Dev

How to create event listener for elements created dynamically without JQuery

From Dev

create event listener to dynamically created google-map marker

Related Related

  1. 1

    Add Event Listener for dynamically created particular element using jquery

  2. 2

    How to add event listener to element created dynamically within prototype?

  3. 3

    jquery - add event listener to dynamically created button

  4. 4

    Add event listener to dynamically created button

  5. 5

    Add data to dynamically created element and bind event

  6. 6

    jQuery - Add click event to a dynamically created element

  7. 7

    Dynamically add event listener

  8. 8

    Event listener for dynamically created html

  9. 9

    Dynamically Created Element and event

  10. 10

    jQuery object-oriented created dom element and add event listener

  11. 11

    Dojo Event dynamically created events not handled

  12. 12

    Adding Event Listener to dynamically created divs

  13. 13

    Binding event to dynamically created element

  14. 14

    Event Binding on Dynamically Created Element

  15. 15

    How to attach an event listener to dynamically added widget content in Dojo toolkit

  16. 16

    How to add a function/event listener to an element created with ES6's template literals?

  17. 17

    Symfony2 add event listener dynamically

  18. 18

    dynamically add event listener for function with variable

  19. 19

    Add event listener to form element added by event listener

  20. 20

    jQuery Tooltip event not firing on dynamically created element

  21. 21

    Dynamically created element not firing click event

  22. 22

    jQuery event not triggering on dynamically created element

  23. 23

    jQuery Tooltip event not firing on dynamically created element

  24. 24

    Why does this dynamically created element not bound to an event?

  25. 25

    Dynamically created element not firing click event

  26. 26

    jquery listen to click event on dynamically created element

  27. 27

    Passing an argument to a event listener from dynamically created buttons

  28. 28

    How to create event listener for elements created dynamically without JQuery

  29. 29

    create event listener to dynamically created google-map marker

HotTag

Archive