Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to subtract text with jQuery

How can I subtract text with jQuery?

I tried to use minus to delete the text, but it doesn't work.

var coluna = $('.coluna').css('width');

In this line, the value outputted is "300px", and I want to remove "px" to get just the number 300.

like image 711
user2154508 Avatar asked Feb 01 '14 01:02

user2154508


1 Answers

instead of using

var coluna = $('.coluna').css('width');

(Which returns a string)

use this:

var coluna = $('.coluna').width();

(Which returns an integer)


If you ever find yourself needing to actually split strings, take a look at substring()

like image 139
Jamie Taylor Avatar answered Oct 26 '22 14:10

Jamie Taylor