Javascript – Left() function in Javascript or jQuery

javascriptjquery

I just want a very handy way to extract the numbers out of a string in Javascript and I am thinking about using jQuery, but I prefer the method that proves to be the simplest. I have requested the "left" attribute of a css block using jQuery like this:

var stuff = $('#block').css("left")

The result of "stuff" is

1008px

I just want to get rid of the "px" because I need to do a parseInt of it. What is the best method? If Javascript had a left() function, this would be very simple. Thanks

Best Solution

Just do a parseInt("1008px", 10), it will ignore the 'px' for you.