I would like to do this:
<div style="float: left; width: 59px; background: transparent url('http://download.com/47.jpg') no-repeat scroll -132px -1px;" class="cIconSmall"> </div>
and I'm thinking I should use this:
$("#YourElementID").css({ float: "left", width: "59px", background: "transparent url('http://download.com/47.jpg') no-repeat scroll -132px -1px" });
Any ideas?
Thanks
Apply multiple CSS properties using a single JQuery method CSS( {key1:val1, key2:val2....). You can apply as many properties as you like in a single call. Here you can pass key as property and val as its value as described above.
To define multiple CSS attributes in jQuery, use the css selector or the addClass() method. Let's see how to do it using css selector. Pair up strings representing property names with the corresponding values.
jQuery has several methods for CSS manipulation. We will look at the following methods: addClass() - Adds one or more classes to the selected elements. removeClass() - Removes one or more classes from the selected elements.
jQuery css() Method The css() method sets or returns one or more style properties for the selected elements. When used to return properties: This method returns the specified CSS property value of the FIRST matched element.
You're thinking correctly. Using the css(map)
method is the way to go.
$(".cIconSmall").css({ float: "left", width: "59px", background: "transparent url('http://download.com/47.jpg') no-repeat scroll -132px -1px" });
http://api.jquery.com/css/
A map of property-value pairs to set.
Might be nicer as a css class, though... then you can just write $(".cIconSmall").addClass("icon47");
but there's a time for everything...
$(".yourClass").css({ float: "left", width: "59px", background: "transparent url('http://download.com/47.jpg') no-repeat scroll -132px -1px" });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With