Solved

Dynamic data not calling class after creation

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
multiple selects 23 62
Google Tag Manager - Add Trigger Using Div class 22 62
ASP.NET - Why is accordion not working? 3 50
Jquery HTML() with ajax... replacing content 2 32
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

726 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