code_junkie

Left() function in Javascript or jQuery

Nov 13th, 2011
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. var stuff = $('#block').css("left")
  2.  
  3. 1008px
  4.  
  5. parseInt(stuff);
  6.  
  7. String.prototype.left = function(n) {
  8. return this.substring(0, n);
  9. }
  10.  
  11. var num = "1008px".left(4);
  12.  
  13. var value = "1080px";
  14. var num = value.replace(/[^d]+/g, '');
  15. // or
  16. var num = value.replace(/D+/g, '');
  17. // or
  18. var num = value.match(/d+/)[0];
Add Comment
Please, Sign In to add comment