Reputation: 4007
i need to set the width of a div container to be 100% - 150px
How can this be achived using jquery?
Upvotes: 0
Views: 266
Reputation: 2481
div = $('div');
parent_width = div.parent().width();
div.width(parent_width - 150);
Upvotes: 0
Reputation: 4629
Try this:
$("#id").width('100%');
var width = $("#id").width();
$("#id").width(width - 150);
JQuery documentation: http://api.jquery.com/width/
Upvotes: 1
Reputation: 570
This should work:
$('#yourdiv').width( $('#yourdiv').width() - 150 )
Also have a look at the jQuery Documentation.
Upvotes: 2
Reputation: 1841
If you're basing it on the window you can use:
var width = $(window).width() - 150;
$("#container").css("width", width);
Upvotes: 0