Simple javascript/jquery append, remove question
Posted
by Scarface
on Stack Overflow
See other posts from Stack Overflow
or by Scarface
Published on 2010-04-01T20:20:39Z
Indexed on
2010/04/01
20:23 UTC
Read the original article
Hit count: 155
jQuery
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>');
© Stack Overflow or respective owner