Simple javascript/jquery append, remove question
- by Scarface
Hey guys, quick question. I have a div that on click will execute a jquery function onclick, and then replace the div with its opposite div which onclick will replace back to the first div just like the favorite function on this site. I am having a simple problem I hope someone can spot or explain to me it is not possible. The function works with the initial two divs that are served directly, but when I click on either of the original two divs, and the function executes and replaces the div with the corresponding div the replacement div does not execute the function. I have to refresh the page to get the original div, which is identical to execute the function. Is the div actually replaced on the page with append, or does it just visually show it? Any advice appreciated.
original div
<div class="unfavorite"><img id="unfavorite_img" src="images/favorite2.png" /></div>
javascript div replacement
$(".favorite").remove();
$(".favoriteholder").append('<div class="unfavorite"><img id="unfavorite_img" src="images/favorite2.png" /></div>');