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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:30:21+00:00 2026-05-28T13:30:21+00:00

I am having trouble getting the new .on click to work using 1.7. For

  • 0

I am having trouble getting the new .on click to work using 1.7.

For dynamically created links, such as the ones generated by clicking the Create button, those links need the same click function as the static links in the DOM.

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>

<script type="text/javascript">

function createDivs(){
content = '<div class="tile-button"><a class="tile-action" href="#" rel="1234" alt="Open">Dynamic Link</a></div>';
$(content).appendTo("#dynamicArea");
$('.tile-action').bind('click',function(){});

}

$(document).ready(function(){
    $('#createButton').on("click", createDivs);

    $('#destroyButton').on("click", function(event){
        $("#dynamicArea").html("");
    });

    $('.tile-action').on("click", function(event){
            var linkalt = $(this).attr("alt");
            var linkrel = $(this).attr("rel");
            alert(linkalt + " " + linkrel);
            return false;
   });
});     
</script>
</head>
<body>
<button id="createButton">CREATE</button> <button id="destroyButton">Destroy :(</button>
<div id="dynamicArea"></div>

<br>
<a class="tile-action" href="#" rel="1234" alt="Open">Link</a><!-- works -->
</body>
</html>

In this simplified example of my problem, when you click the Create button a dynamic link appears. When you click that nothing happens and those dynamic links do not call the alert like the static link does.

  • 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-28T13:30:22+00:00Added an answer on May 28, 2026 at 1:30 pm

    on method takes second argument as the selector on which the event should be triggered which you are missing. Also the root element should be the container which will contain the dynamic elements. In your case it is #dynamicArea. Try this.

       $("#dynamicArea").on("click", ".tile-action", function(event){
                var linkalt = $(this).attr("alt");
                var linkrel = $(this).attr("rel");
                alert(linkalt + " " + linkrel);
                return false;
       });
    

    You should understand the working of on. We are selecting #dynamicArea element and using on method on it passing the selector .tile-action. jQuery will attach a click event on #dynamicArea and whenever any element is clicked inside #dynamicArea the event will be bubbled to #dynamicArea. At this point it will try to see if the selector which we have passed as second parameter to on matches or not. If it matches then it triggers the event otherwise it will not do anything just bubble up the event if we don’t stop it.

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

Sidebar

Related Questions

I'm having trouble getting tinyMCE to work with the new jQuery 1.4.2 on IE6.
I am having trouble getting the input values of dynamically created controls in a
I'm completely new to Visual Studio and I'm having some trouble getting a project
I'm new to Watir and I've having a little trouble getting logged in in
I'm having trouble getting a rotary encoder to work properly with AVR micro controllers.
I'm having trouble getting the following to work in SQL Server 2k, but it
I'm new to ASP.NET MVC; something I'm having trouble with is getting data from
I'm using mootools-1.2.3 at the moment and I'm having trouble getting a variable to
I'm just getting into using prototypal JavaScript and I'm having trouble figuring out how
Im having some trouble getting Ajax.ActionLink to work how I expect. In /views/layout/_Layout.cshtml I

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.