How to remove 20 pixels from an element with Jquery

Asked

Viewed 38 times

2

I need to re-calculate the size of an INPUT TEXT element because a button of 20 pixels will be dynamically added next to it.

I tried that and it didn’t work

 $(this).width(function () { $(this).width() - 20 });

1 answer

2


The method .width() It’s a getter, it just goes for the value, not write. You have to use .css() for that reason.

var tamanhoInicial =  $(this).width(); // ou $(this).css('width');
$(this).css('width', tamanhoInicial - 20);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.