1

I have two divs, box and stylewidth. stylewidth is a child of box, which I've tried to make as large as stylewidth in a function. to that end I've added this line.

$("#box").width(("#styleWidth").width); 

The problem is, box doesn't change in size, and I'm not sure why. is this the correct method?

Captain Dando
  • 497
  • 2
  • 11
  • 30
  • have a look at this question http://stackoverflow.com/questions/6593425/best-method-to-fit-a-child-div-to-its-parents-width – Calum Jan 30 '13 at 09:55

3 Answers3

4

You forgot the parenthesis on the inner width() function and the dollarsign, and make sure you wrap it in document.ready or add it after the elements are loaded in the DOM:

$("#box").width( $("#styleWidth").width() );
adeneo
  • 312,895
  • 29
  • 395
  • 388
1

You forgot the jQuery dollar sign (before #styleWidth) and .width is a function, so it takes ().

$("#box").width($("#styleWidth").width()); 
jfvoliveira
  • 104
  • 2
  • 7
0

Are you sure you can't solve this problem with css?

You may be able to simply use width:100% assuming the positioning and document structure allow this.

Eamon Nerbonne
  • 47,023
  • 20
  • 101
  • 166