title: javascript code for removing last item from string if it exists
body: <p>i have a code which is avaliable in the following fiddle </p>
  
  <p><strong><a href="http://jsfiddle.net/wbagktuw/" rel="nofollow">http://jsfiddle.net/wbagktuw/</a></strong></p>
  
  <p>code is like this </p>
  
  <pre><code>&lt;a data-rel="http://mydomain.domian.com?z_9.asp&amp;rpttype=298&amp;sotBy=2sortOrder=1&amp;pagenum=2"&gt;
  
  $(document).ready(function() {
      var urlval = $("a").attr('data-rel');
      alert(urlval);
  });
  </code></pre>
  
  <p>i am trying to remove the &amp;pagenum=2 from the url if it exists, if it does not exists, then no problem, if exists, i want to remove that </p>
  
  <p>what should i try here </p>