简体   繁体   中英

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

我认为应该

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM