?
Solved

Dynamic data not calling class after creation

Posted on 2014-01-29
3
Medium Priority
?
173 Views
Last Modified: 2014-01-29
I have a table row I append to a table. One of the items has a class attached, and the class is supposed to have an onclick event. When I click on the dynamic row it doesn't run the function. The part that isn't working is the remove link. It doesn't call the Remover function.

<a href="#" class="Remover" id="Remove' + msg[0].SenID + '">Remove</a>

Open in new window


$('#tblScenario').append('<tr><td class="divs">' + msg[0].Low + '</td><td class="divs">' + msg[0].Avg + '</td><td class="divs">' + msg[0].High + '</td><td class="divs">' + msg[0].Count + '</td><td><a href=\"FilterDetails.aspx?pid=' + msg[0].SenID + '\" target=\"_blank\">Details</a> </td><td><a href="#" class="Remover" id="Remove' + msg[0].SenID + '">Remove</a></td></tr>');

Open in new window

0
Comment
Question by:NickMalloy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39818724
when you insert dynamically element in your page you need to use jQuery.on :
http://api.jquery.com/on/ but the main selector is acontainer of this element :

jQuery("#tblScenario").on("click", ".Remover", function(event) {
      // remove the line for example :
      // $(this).closest("tr").remove();
});

Open in new window


"#tblScenario" is the best container because it's the table
but you can choose a div around this table, or the document itself, in the background "jQuery" is just looking inside each time a click appear to know if the target is your class
0
 

Author Comment

by:NickMalloy
ID: 39818805
when I try and add that code, I get.

0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'on'
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 1200 total points
ID: 39818902
your jQuery library is very old...
use delegate or live instead

jQuery(".Remover").live("click",function(event) {
      // remove the line for example :
      // $(this).closest("tr").remove();
});

Open in new window

0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question