?
Solved

Dynamic data not calling class after creation

Posted on 2014-01-29
3
Medium Priority
?
175 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 83

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 83

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
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…
Suggested Courses

840 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