Replace Div Content onclick

前端 未结 6 994
名媛妹妹
名媛妹妹 2020-12-06 07:48

I know nothing about jQuery but want to achieve something really important.

I want to have a button/link that will replace the div content and if I press that button

6条回答
  •  情深已故
    2020-12-06 08:21

    A Third Answer

    Sorry, maybe I have it correct this time...

    jsFiddle Demo

    var savedBox1, savedBox2, state1=0, state2=0;
    
    jQuery(document).ready(function() {
        jQuery(".rec1").click(function() {
            if (state1==0){
                savedBox1 = jQuery('#rec-box').html();
                jQuery('#rec-box').html(jQuery(this).next().html()); 
                state1 = 1;
            }else{
                jQuery('#rec-box').html(savedBox1); 
                state1 = 0;
            }
        });
    
        jQuery(".rec2").click(function() {
            if (state1==0){
                savedBox2 = jQuery('#rec-box2').html();
                jQuery('#rec-box2').html(jQuery(this).next().html()); 
                state2 = 1;
            }else{
                jQuery('#rec-box2').html(savedBox2); 
                state2 = 0;
            }
        });
    });
    

提交回复
热议问题