2

I'm trying to modify the width of a div. What am I doing wrong?

$('#foo')

[<div class=​"bar" id=​"foo" style=​"width:​ 40%">​</div>​]

$('#foo').css('style','width:50%')

[<div class=​"bar" id=​"foo" style=​"width:​ 40%">​</div>​]
Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
JZ.
  • 21,147
  • 32
  • 115
  • 192

2 Answers2

9

I think it should be

$('#foo').css('width','50%')
Milindu Sanoj Kumarage
  • 2,714
  • 2
  • 31
  • 54
6

Actually you can follow either one of the following two methods.

$('#foo').css('width','50%')

Or

$('#foo').css({width:'50%'})

The second method is used to change multiple properties at one.

Tharindu Kumara
  • 4,398
  • 2
  • 28
  • 46