Solved

Dynamic data not calling class after creation

Posted on 2014-01-29
3
172 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 300 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…

691 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