Refactor Jquery code into function for reuse
<p>Looking for some assistance if possible.</p>

<p>I have created some jquery code that does the job, but i feel is a bit cluncky, and would like to refactor it correctly...</p>

<p>At the moment the code responds to a click by the user, it checks on server if the user is allowed to vote, if so, it processes the vote via ajax, and moves the vote accordingly. </p>

<p>However, it is currently set up to run only when the "vote up" link is clicked, where it adds one to the vote count. What I also want to do is detract 1 from the vote count when the user clicks on the link with class="vote down", but i dont want to repeat the same code all over again, for this.</p>

<p>Wondering if there was anyway to package all the code into a function, and say "add one if vote up is clicked, detract one if vote down is clicked.</p>

<p>Many thanks</p>

<pre><code>&lt;a href="link class="vote up"&gt; Vote Up &lt;/a&gt;
&lt;a href="link class="vote down"&gt; Vote Down&lt;/a&gt;




     $('body#true .voteUp').click(function(){

  // Get the song meaning
  $thisLink = $(this);
  var idSm = $(this).parents("div:eq(1)").attr("id");
   //Validate that user isnt rating their own song meaning
   $.getJSON('http://localhost:8500/mxRestore/model/mdl_songs.cfc?method=getRateSm&amp;returnFormat=json&amp;queryformat=column', 
   {idSm: idSm}, 
   function(data){
    var bVoteAllowed = data.ROWCOUNT &lt; 1;
    if(bVoteAllowed){
    // User can vote
     $.getJSON('http://localhost:8500/mxRestore/model/mdl_songService.cfc?method=rateSm&amp;returnFormat=json&amp;queryformat=column', 
     {idSm:idSm,action:true})
                                   // Change vote accordingly
     var totalQuantity = 0;
     var quantity = $thisLink.parent().parent().children('.rateValue').text();
     quantity = parseInt(quantity);
     totalQuantity = quantity + 1; 
     $thisLink.parent().parent().children('.rateValue').text(String(totalQuantity)).effect("highlight", {}, 3000);
    }else {

     $thisLink.text("you are not allowed to vote") 
    }

   })
   return false

 })
</code></pre>
