user1530249
user1530249

Reputation: 1057

I have tried to use the jQuery css function to change the width of element with a class, am I using the right function?

Is it possible to change the value of width below using jQuery

 <div style="width:75%" id="twitter" class="bar"></div>
 <div style="width:75%" id="other2" class="bar"></div>
 <div style="width:75%" id="something" class="bar"></div>

I have tried

jQuery(document).ready(function($) {
   $('#twitter').css({
   "width":"5%",
   });
)};

Here is my jsfiddle

http://jsfiddle.net/LSwwB/1/

Thanks

Upvotes: 0

Views: 62

Answers (3)

Roko C. Buljan
Roko C. Buljan

Reputation: 206467

   jQuery(function($) {
        $('#twitter').css({width:"5%"}); // <-- extra ','
   });  // <-- instead of mustache add a beard to that fella

Upvotes: 0

Mooseman
Mooseman

Reputation: 18891

You had a couple errors in your code. Fixed on http://jsfiddle.net/LSwwB/3/.

Line 3: no comma after the last property.
Line 5: )}; should be });

Upvotes: 3

isherwood
isherwood

Reputation: 61079

That should work fine (with the syntax fixes posted by others). Slighly simpler is jQuery's Width function: http://api.jquery.com/width/#width2

$('#twitter').width('5%');

Upvotes: 0

Related Questions