change css with jquery
What is the best way to change the css of an element using jquery? I have a list of elements displayed one per line and I want to display them inl开发者_运维百科ine, dynamically.Should I use
.css({"properties"})
And write a whole bunch of code ? Any other suggestions ? Thanks.
If the styles are going to be static then what you can do is externalize the styles into a stylesheet and use jQuery to add CSS classes to your element.
Select the elements you wish to change with the selector, then use the .css()
method to change the display property.
$('.my-element-class').css('display', 'inline');
If you need to change multiple properties at once, using an object property map is easier than repeatedly calling .css()
.
$('.my-element-class').css({ 'display': 'inline', 'marginLeft': '100px' });
Note the use of 'marginLeft' rather than 'margin-left', the css()
operator expects the values to be in camelCase I believe.
You can change/add properties like this:
element.css("display","inlne");
You can add new class in your CSS sheet and then simply toggle it on the parent element.
Or use .css({'display':'inline'})
.
Hi if i understand you want to change all properties? Then i think you can use class, addClass,removeClass for this
精彩评论