How to remove 20 pixels of an element with Jquery

2

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

I tried this and it did not work

 $(this).width(function () { $(this).width() - 20 });
    
asked by anonymous 27.04.2015 / 22:00

1 answer

2

The .width() method is a getter, it will only fetch the value, not write. You have to use .css() for this.

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