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 8753963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:31:48+00:00 2026-06-13T13:31:48+00:00

i am trying to activate a jQuery ‘replaceWith’ function on click to replace div1

  • 0

i am trying to activate a jQuery ‘replaceWith’ function on click to replace div1 with div2 and then use ‘replaceWith’ again to replace div2 with div1 on click.

everything is working except, when clicking on div2, div1 does not re-appear.

my code is:

$(document).ready(function(){
$("#open_doors").click(function(){
$("#leftdoor_inner").animate({"left": "-=164px"}, 'slow');
$("#leftdoor_outer").animate({"left": "-=74px"},'slow');
$("#rightdoor_inner").animate({"left": "+=164px"},'slow');
$("#rightdoor_outer").animate({"left": "+=74px"},'slow');
$("#open_doors").replaceWith($("#close_doors"));
});
$("#close_doors").click(function(){
$("#leftdoor_inner").animate({"left": "+=164px"},'slow');
$("#leftdoor_outer").animate({"left": "+=74px"},'slow');
$("#rightdoor_inner").animate({"left": "-=164px"},'slow');
$("#rightdoor_outer").animate({"left": "-=74px"},'slow');
$("#close_doors").replaceWith($("#open_doors"));
});
});​

the nearly working jsfiddle is here:

http://jsfiddle.net/9zsdN/2/

i’m pretty sure my question has been answered at the link below but i can’t figure out how to apply it to my exact code.

Events not registering after replaceWith

thank you.

  • 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-13T13:31:49+00:00Added an answer on June 13, 2026 at 1:31 pm

    instead of replaceWith you can just use show() and hide()

     $(document).ready(function(){
          $("#open_doors").click(function(){
            $("#leftdoor_inner").animate({"left": "-=164px"}, 'slow');
            $("#leftdoor_outer").animate({"left": "-=74px"},'slow');
            $("#rightdoor_inner").animate({"left": "+=164px"},'slow');
            $("#rightdoor_outer").animate({"left": "+=74px"},'slow');
            $("#open_doors").hide();
            $("#close_doors").show();
          });
         $("#close_doors").click(function(){
             $("#leftdoor_inner").animate({"left": "+=164px"},'slow');
             $("#leftdoor_outer").animate({"left": "+=74px"},'slow');
             $("#rightdoor_inner").animate({"left": "-=164px"},'slow');
             $("#rightdoor_outer").animate({"left": "-=74px"},'slow');
             $("#close_doors").hide();
             $("#open_doors").show();
         });
       });
    

    Demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to figure out how to activate the callback in one jquery
I've been trying for some time to activate a jQuery UI accordion's panel from
I am trying to activate Pinch-Zoom in my app made on Jquery Mobile (Rhomobile
I'm working on http://www.aceaofmidland.com/ and I'm trying to use jQuery and jQuery.cycle to cycle
I have this jquery function to automatically replace sertain characters with others: jQuery(function() {
I'm trying to use tabs to activate both a Coda slider in the left
I'm trying to use jquery to update a database using .ajax(). The idea is
I'm trying to create a interval call to a function in jQuery, but it
i am using jquery tabs, and trying to get pagination in each one, everything
I am trying to activate a profile in my maven pom as follows:- <profile>

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.