Reputation: 1342
In short, is there a way to set the outerWidth?
$.outerWidth(true, newValue)
Update: I found some addons that do this, although I need one function definition not 3 addons to do this.
Upvotes: 4
Views: 5197
Reputation: 1692
You were pretty close. With jQuery 1.8+, just use:
.outerWidth(newValue, true);
Also works for:
It actually became a setter with jQuery 1.8. That is 1 year after you posted your question. Moreover, it was listed in the changelog, but nobody updated the documentation which explains that it might have been missed by many.
If you have jQuery 1.7.2 or older, see Xeo's answer (on this page) or use jquery-ui 1.8.4+ which automatically enhances those methods into getters/setters (since in jQuery 1.8, those methods were actually ported from jquery-ui).
Upvotes: 7
Reputation: 357
Is this what you're looking for?
var a = $('element');
actualWidth = a.outerWidth(true),
desiredWidth = 1000,
difference = desiredWidth - actualWidth,
a.css('width',difference);
Upvotes: 4
Reputation: 3891
If you want to set the width of an element, you can use these examples
var a = $("#element");
a.width(10);
a.css("width", "10px");
Upvotes: 1