user2154508
user2154508

Reputation: 345

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.

Upvotes: 5

Views: 324

Answers (1)

Jamie Taylor
Jamie Taylor

Reputation: 4765

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()

Upvotes: 7

Related Questions