Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Anchor Tag onclick event not firing inside a tile

    Hi,

    I am dynamically creating tiles using Jquery. When user enters text in the textbox and click on "Create" button, tile will be created. When I click on created tile name/title, I want a function to be fired. But its not firing. Help is much appreciated.

    below is my script:-
    <html>
    <head>
    <script src="jquery-1.10.2.js" type="text/javascript"></script>
    <script>
    $(document).ready(function(){
    $("#CreateDIV").click(function(){

    $TileContainer = $('.msax-TileContainer');

    $tileMarkup =$('<div class="tileview-tile-content" style="display:inline;margin-right:10px"><a onclick="javascript:AddToList();" href="#"><div class="tileview-tile-detailsBox">HelpDesk</div></a></div>');

    $tileMarkupText = $tileMarkup.find('.tileview-tile-detailsBox');

    $tileMarkupText.text($("#txt1").val())
    $TileContainer.append($tileMarkup);
    });
    function AddToList()
    {
    alert("Clicked");
    }
    });
    </script>
    </head>
    <body>
    <span class="msax-TileContainer"></span>
    <input type="text" id="txt1">
    <button type="button" id="CreateDIV">Create</button>
    </body>
    </html>

    Thanks.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,032
    Thanks
    0
    Thanked 248 Times in 245 Posts
    Use delegated event. Remove the onclick in the html string.

    Code:
    $('.msax-TileContainer').on('click', '.tileview-tile-content a', function(e) {
        AddToList();
    });

  • Users who have thanked glenngv for this post:

    srinivasc_it (09-27-2013)

  • #3
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That worked thanks :-)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •