I'm trying to add functionality that toggles an image on click event, inserts row into db and binds a new event which removes the row on click event.
this works but i was wonder if there is a more elegant method: add_imgoing = function() { $(\'.add_imgoing\').click(function () { var show_id = $(this).attr(\'id\'); var user_id = '.PA::$login_uid.'; $(this).attr({ src: \'Themes/Beta/images/button-remove.jpg\' }); $(this).removeClass(\'imgoing\').addClass(\'remove_imgoing\'); $(this).unbind(\'click\'); $.get(\'ajax/add_user_show.php\',{ user_id: user_id, show_id: show_id },remove_imgoing); }); } remove_imgoing = function() { $(\'.remove_imgoing\').click(function () { var show_id = $(this).attr(\'id\'); var user_id = '.PA::$login_uid.' $(this).attr({ src: \'Themes/Beta/images/button-imgoing.jpg\' }); $(this).removeClass(\'remove_imgoing\').addClass(\'imgoing\'); $(this).unbind(\'click\'); $.get(\'ajax/remove_user_show.php\', { user_id: user_id, show_id: show_id },add_imgoing); }); }