Since you are dynamically adding new items to the DOM, you will have to register the click handler again on the new items You can use docs.jquery.com/Events/live for this.
Since you are dynamically adding new items to the DOM, you will have to register the click handler again on the new items. You can use docs.jquery.com/Events/live for this.
Live will only work if the selector is exactly the same. In this case I think the selector is unique to each DOM element. – tvanfosson May 2 '09 at 23:14 Thanks @wolfr.
I didn't know this existed. – Daniel A. White May 2 '09 at 23:15 Great answer.
I knew my js code worked, but couldn't figure out what was happening... after reading your answer, I realized I was binding to anchor tags rendered via asp. Net mvc webgrid... again, thanks for the help @Wolfr – Richard B Jul 8 at 0:34.
Just demonstrating the use of .end() for a more fluid solution: $(function() { $(". Add2"). Click(function(){ return $(this).
Parents(". Place") . Find(".
Add2") .hide() .end() . Find(". Actions") .
Append("Added! Undo"); }); $('. Undoadd2').
Live('click', function(){ return $(this). Parents(". Place") .
Find(". Actions") . Find("span.
Added, a. Undoadd2") .remove() .end() .end() . Find(".
Add2") .show(); }); }).
Since you are dynamically adding new items to the DOM, you will have to register the click handler again on the new items. JQuery sets the handler when you call $('...'). Click(...).
The click handler isn't being picked up when you append the element to the DOM. Try using jQuery to register the click handler by changing the line(s) that look like: $("#" + placeId + " . Actions").
Append("Added! Undo") To $("#" + placeId + " . Actions").
Append("Added! Undo"); $('#' + placeId + " . Actions").
Find("span:last"). Find("a"). Click( function() { undoAddPlace( placeId ); return false; }); You might be able to do it more simply, but it looks like you could be adding more than one span to the paragraph so I went conservative.
You could also probably chain off append, but I thought the reselect made the point clearer.
Wow! Thanks to all of you! I've read about the live event and final working code is: $(function() { $(".
Add2"). Click(function(){ var placeId = $(this). Parents(".
Place"). Attr("id"); $("#" + placeId + " . Add2").hide(); $("#" + placeId + " .
Actions"). Append("Added! Undo"); return false; }) $('.
Undoadd2'). Live('click', function(){ var placeId = $(this). Parents(".
Place"). Attr("id"); $("#" + placeId + " . Actions").
Find("span. Added, a. Undoadd2").remove(); $("#" + placeId + " .
Add2").show(); return false; }); Previously I used remove() for delete the text that offers to perform the action. I've changed it for hide/show so I don't have to use live also in the first function. Thanks again!
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.