jquery selectors - smart way to rewrite this function -


i have this, , showing div if user clicked 1 button , not showing if user clicked other. working dumb way repeatition

$j(document).ready(function() {     $j('#button1').click( function () {          var data = $j("form").serialize();         $j.post('file.php', data, function(response){                    $j("#response").show();         });     });     $j('#button21').click( function () {          var data = $j("form").serialize();         $j.post('file.php', data, function(response){                    //do else                    });     }); });  

i'd adding class selected buttons , pull event.target id click function:

    $j('.buttons').click(function(e) {         var buttonid = e.target.id,             data = $j("form").serialize();          $j.post('file.php', data, function(response) {             switch (buttonid) {                 case "button1":                     $j("#response").show();                     break;                 case "button21":                     //do else                     break;             }         });     }); 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -