if(!show_add_contact){ var previous_content = $('#content').html(); var show_add_contact = true; } <%= toolbar(:profile => @tie.receiver_subject).html_safe %> $('#content').html("<%= escape_javascript(render(:partial => "ties/new")) %>"); $('#close_add_contact').click(function() { $('#content').html(previous_content); });