Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8835411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:15:21+00:00 2026-06-14T09:15:21+00:00

when i click the add image button a new image appears when i click

  • 0

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

http://jsfiddle.net/6MmMe/37/

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();
  }
);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:15:22+00:00Added an answer on June 14, 2026 at 9:15 am

    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:

    <!DOCTYPE html>
    <html>
    <head><script type='text/javascript' src='http://code.jquery.com/jquery-1.8.2.js'></script>
    <style type='text/css'>
    div div { color:red; display:none}
    </style>
    <script>
    $(function(){
    $('body > div').hover(function(){
        // show "add image"
        $('div', this).show(); 
    }, function(){
        // hide "add image" and reet image src. 
       $('div', this).hide();
       $('img', this).attr("src", "http://imgs.zinio.com/magimages/500299032/2012/416238969_170.jpg");
    })
    // top-level click handler
    .click(function(){
            $('img', this).attr("src", "http://www.onlinegrocerystore.co.uk/images/goodfood.jpg");              
        });
    }); 
    
    </script>
    </head>
    
    <body>
      <div>
        <img src="http://imgs.zinio.com/magimages/500299032/2012/416238969_170.jpg" alt="Nov-12" title="Food Network Magazine" class="cover">
        <div href="#">add image</div>
    </div>
    
    </body>
    </html>
    

    If you want to do this mostly in CSS, just toggling a class with jQuery, you can do this:

    <!DOCTYPE html>
    <html>
    <head><script type='text/javascript' src='http://code.jquery.com/jquery-1.8.2.js'></script>
    <style type='text/css'>
    body > div {
    background-image: url(http://imgs.zinio.com/magimages/500299032/2012/416238969_170.jpg);
        width: 170px;
        height:222px;
        position:relative;
    }
    body > div.newImage:hover {
        background-image: url(http://www.onlinegrocerystore.co.uk/images/goodfood.jpg);
        width: 249px;
        height:274px;
    }
    div div { 
        color:red;
        position:absolute;
        bottom:0;
        margin-bottom:-16px;
        display:none;
    }
    div:hover div {
        display:block;
    }
    </style>
    <script>
    $(function(){
        $('body > div').click(function(){
           $(this).addClass('newImage');
        }).hover(false, function(){
            $(this).removeClass('newImage');
        });​
    }); 
    </script>
    </head>
    <body>
        <div>
            <div>add image</div>
        </div>
    </body>
    </html>
    

    If you really prefer to add/remove things, you can do it like this:

    <!DOCTYPE html>
    <html>
    <head><script type='text/javascript' src='http://code.jquery.com/jquery-1.8.2.js'></script>
    <style type='text/css'>
    div div { color:red;}​
    </style>
    <script>
    $(function(){
        $('body > div').hover(function(){
            // show "add image"
            $(this).append('<div>add image</div>');
        }, function(){
            // hide "add image" and reset image src. 
           $('div', this).remove();
           $('img', this).attr("src", "http://imgs.zinio.com/magimages/500299032/2012/416238969_170.jpg");
        })
        // top-level click handler
        .click(function(){
            $('img', this).attr("src", "http://www.onlinegrocerystore.co.uk/images/goodfood.jpg");              
        });
    }); 
    </script>
    </head>
    <body>
        <div>
            <img src="http://imgs.zinio.com/magimages/500299032/2012/416238969_170.jpg" alt="Nov-12" title="Food Network Magazine" class="cover">
        </div>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Project: http://design.vitalbmx.com/fave/news.html When I click Add to favorites button (under main pic), in Chrome
How can I add click event to newly added item of menu? Below is
When I click on Add button , the formAddNewRow form opens , but I
I am having a gridview which consist of add button for adding a new
I want to add event to button image to move the pan of my
I insert dynamically some images used as buttons and add an onClick event. $(img.image_edit_customer).live(click,
When I click Add to Compare on a product, a message stating that such-and-such
I am trying to build a shopping cart site. When a user click add
Im trying to add click events to shapes within a visio file.. I have
I am trying to add click event to one of the widgets that use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.