var addClose = function() { $('#edit').click(function() { q = $('#question div label'); q.html(''); $('#edit').text('Close'); edit = $('#edit'); edit.attr('id', "close"); addEdit(); }); }; var addEdit = function() { $('#close').click(function() { text = $('#question textarea').val(); label = $('#question label'); label.html(text); close = $('#close'); close.text('Edit'); close.attr('id', "edit"); addClose(); }); }; addClose();