Solved

Dynamic data not calling class after creation

Posted on 2014-01-29
3
170 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
  • 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

825 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