when i click the add image button a new image appears
when i click the new image can i revert it back to my previous state using jquery…showing the previous image with add image on hover
providing my js code below
$("div").hover(
function () {
$("<div>add image</div>").click(function() {
$(this).parent().unbind("hover").children("img").attr("src", "http://www.onlinegrocerystore.co.uk/images/goodfood.jpg");
$(this).remove();
}).appendTo(this);
},
function () {
$(this).find("div:last").remove();
}
);
The problem is that you are handling the first div, then removing it. There are a few ways to accomplish what I think are your goals.
I would recommend doing it with hide/show for easier management.
If you want to do this in jQuery, you can do it like this:
If you want to do this mostly in CSS, just toggling a class with jQuery, you can do this:
If you really prefer to add/remove things, you can do it like this: