We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Bind html event to child elements.

Home Forums Puzzles Bind html event to child elements.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #16267
    zjbcool
    Customer

    Hello,
    I want to bind a click event for a ul element,it has several li elements.And I use puzzle like this screenshot.What I want is that when I click a element , it shows it’s index.But it always shows the last one’s.I wonder how to implement it,thanks! :wacko:

    #16271
    zjbcool
    Customer

    Although I implement is with code,But I’m curious how to do it with puzzle.
    The code like this

    app.ExternalInterface.bindClickToAnnotation = function (list) {
                for (var i = 0; i < list.length; i++) {
                    (function (j) {
                        document.getElementById(list[j]).onclick = function () {
                            var sel = list[j];
                        };
                    })(i);
                }
            };
    #16443

    Hi,

    You can create a procedure which assigns the onclick event to a single element. Then you can use this procedure inside the loop. This way it won’t override the previous event listeners.

    Chief 3D Verger | LinkedIn | Twitter

    #16445
    zjbcool
    Customer

    Hi,
    Thankyou,Yuri.I did it.It’s usefull for binding event dynamically. :yahoo:

    #16447

    :good:

    Chief 3D Verger | LinkedIn | Twitter

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.