Skip to content
Loading
How to swap two div using jquery   
  • Yogeshkumar Hadiya
    Are you trying to make tab like page ? Like two tab login and sign up. When click in login show login form below and when click on sign up show sign up form.
  • Kiran Mohanty
    Hi,
    If you are trying to display two different divs based on some condition , then here you go. 
    1. <div id="divA" class="hide">    
    2.    div A  
    3. div>    
    4.     
    5. <div id="divB" class="hide">    
    6.     div B    
    7. div>    
    8.     
    9. $("button").click(function(){    
    10.     var val1 = $('#div1').html(),    
    11.         val2 = $('#div2').html();    
    12.     $('#div1').html(val2);    
    13.     $('#div2').html(val1);    
    14.        
    15. });  
    16.   
    17. function someFunc(){  
    18.  if(condition){  
    19.    $("#divA").show();  
    20.    $("#divB").hide();  
    21.  }  
    22.  else {  
    23.     $("#divA").hide();  
    24.     $("#divB").show();  
    25.  }  
    26. }  
     
  • Sachin Singh
    please explain what do you mean by swap?
    otherwise , here you go
    1. "div1">  
    2.     I am div1!  
      
  •   
  • "div2">  
  •     I am div2!  
  •   
  •   
  •   
  • $("button").click(function(){  
  •     var val1 = $('#div1').html(),  
  •         val2 = $('#div2').html();  
  •     $('#div1').html(val2);  
  •     $('#div2').html(val1);  
  •      
  • }); 
  •