0

Depending on amout of <div clas="product"></div> I'm trying to set width for .productholder

 <div class="productholder">
    <div clas="product"></div>
    <div clas="product"></div>
    <div clas="product"></div>
    <div clas="product"></div>
    <div clas="product"></div>
 </div>

I can set fix width for .product if this will help.

I have tried this, but don't seems to be working:

var width = 0;
$('.product').each(function() {
    width += $(this).outerWidth( true );
});
$('.productholder').css('width', width + 250);

Thank you for your help in advance.

1
  • missing an s on class in each of <div class="product"> Commented Oct 6, 2009 at 22:43

2 Answers 2

2

Have you tried specifying a unit?

var width = 0;
$('.product').each(function() {
    width += $(this).outerWidth( true );
});
$('.productholder').css('width', width + 250 + 'px');

By the way, <div class="productholder"> width will grow to accommodate the width of the inner <div> elements

EDIT:

Your code does work as is - Working Demo. Add /edit to the URL to see the code.

Does <div class="productholder"> have any text content? Are you specifying a height for it?

Sign up to request clarification or add additional context in comments.

2 Comments

i tried that. Div is absolute in relative container. Product themselves are floating; Div will not extend due to the fact that the div holding it has fixed width
My stupidity! Sorry. Messed something up in .js file. Many thanks for your help!
1

Will this work for you?

 var holder = $('.productholder');
 var width = holder.find('.product').length * 250;
 holder.css('width', width + "px");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.