jQuery - how to load content in a common div from two differnet events?
<p>I am not a JS ninja hence I am asking for some guidance here. I have following scenario</p>

<ol>
<li>page loads and commondiv is hidden</li>
<li>if user clicks button showeditform, I load editform in commondiv and show the commondiv</li>
<li>if user clicks button showeditform and editform is visible, remove it and hide commondiv</li>
<li>if user clicks button showpasswordform and if the editform is visible and I remove editform and show passwordform</li>
<li>if user clicks button showpasswordform and if the passwordform is visible, remove it and hide the common div</li>
<li>if user clicks button showeditform and if the passwordform is visible and I remove passwordform and show editform</li>
</ol>

<p>As of now, I have set up flags and if elses but its not very good way to do it. How can I achieve this using minimum of jQuery code?</p>

<p><em>Update</em>: Following is my attempt</p>

<pre><code>$('a.editpo, a.resetpass').click(function(event){
    event.preventDefault();
    var urlToCall = $(this).attr('href');
    var hyperlinkid = '#'+$(this).attr('id');
    var targetId = $(this).attr('id').match(/\d+/);
    var targetTrDiv = '#poformloadertr_'+targetId;
    var targetTdDiv = '#poformloadertd_'+targetId;
    var toToggle = $('#resetuserpassform_'+targetId).is(':visible') || $('#account-home-container-'+targetId).is(':visible') ;
    console.log(toToggle);
    if(toToggle == true || $(targetTdDiv).html()==''){
        $.ajax({
            url:urlToCall,
            success: function(html){
                $(targetTdDiv).html(html);
                $(targetTrDiv).show();
            }
        });
    }else{
        $(targetTrDiv).hide();
        $(targetTdDiv).html('');
    }

});
</code></pre>

<p>The <code>editpo</code> and <code>resetpass</code> are classes applied on hyperlinks in column of table, namely Edit personal info and reset pass, clicking these load up the form in a <code>tr&gt;td</code>.  As I said, am not good at JS and specially jQuery, hence if you feel that code can be optimised at some step please feel free to do so. Thanks!</p>
