Jquery replacewith not working correctly?

1. You have to use live() to attach a handler to the event for all elements which match the current selector, now and in the future.

$(document). Ready(function() { $(". CheckOut").

Live('click', function() { var $this = $(this), $currentRow = $this. Closest("tr"); $currentRow . RemoveClass("checkedIn") .

AddClass("checkedOut"); $this. ReplaceWith(''); }); $(". CheckIn").

Live('click', function() { var $this = $(this), $currentRow = $this. Closest("tr"); $currentRow . RemoveClass("checkedOut") .

AddClass("checkedIn"); $this. ReplaceWith(''); }); }); 1. You have to use .live() to attach a handler to the event for all elements which match the current selector, now and in the future.2.

You were doing an unnecessary re-constructing of the variable currentRow. I added a $ sign, so you know it's already a jQuery object, and not to re-construct it. In addition, I added code to cache the $currentRow and $this objects, so you won't have to lookup the DOM every time you want to manipulate them.

1 ah thank you sir that did it! – Error1f1f Aug 17 at 16:00.

Because you're adding the Check In button dynamically (when you click the Check Out button), your click event listener is not going to be attached to it. You could use live instead: $(document). Ready(function() { $(".

CheckOut"). Live("click", function() { //Your event handler code }); $(". CheckIn").

Live("click", function() { //Your event handler code }); } You will need to use live for both, because after the first replacement, a new . CheckOut element is dynamically added to the page.

Instead of replacing you can just change the attribute values which will preserve the event handlers you attached to buttons. $(document). Ready(function() { $(".

CheckOut"). Click(function() { $(this). Closest("tr").

RemoveClass("checkedIn"). AddClass("checkedOut"); $(this) . Attr({ title: "Check In", class: "checkIn", value: "true", name: "check_in" }) .

Find("img"). Attr({ src: "../images/check. Png", alt: "Check In" }); } ); $(".

CheckIn"). Click(function() { $(this). Closest("tr").

RemoveClass("checkedOut"). AddClass("checkedIn"); $(this) . Attr({ title: "Check Out", class: "checkOut", value: "true", name: "check_out" }) .

Find("img"). Attr({ src: "../images/minus. Png", alt: "Check Out" }); } ); }).

An alternative to existing answers would be one handler for both check in and check out: $(". CheckIn, . CheckOut").

Live('click', function() { var $this = $(this), $currentRow = $this. Closest("tr"), checking = $this. HasClass("checkIn"), classToAdd = ckecking?"checkedOut" : "checkedIn", classToRemove = ckecking?

"checkedIn" : "checkedOut", buttonTitle = checking? "Check Out" : "Check In", buttonName = checking?"check_out" : "check_in", imgSrc = checking? "minus" : "check"; $currentRow.

RemoveClass(classToRemove) . AddClass(classToAdd); $this. ReplaceWith(''); } ).

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.

Related Questions