JZ.
JZ.

Reputation: 21907

Changing CSS style using jquery

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>​]

Upvotes: 2

Views: 5592

Answers (2)

Tharindu Kumara
Tharindu Kumara

Reputation: 4458

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.

Upvotes: 6

Milindu Sanoj Kumarage
Milindu Sanoj Kumarage

Reputation: 2783

I think it should be

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

Upvotes: 9

Related Questions