Everything related to appearance. Usually, this is CSS.
Sets the value of a single CSS property.
x$( selector ).setStyle( property, value );
String
is the name of the property to modify.String
is the new value of the property.x$('.flash').setStyle('color', '#000');
x$('.button').setStyle('backgroundColor', '#EFEFEF');
Returns the value of a single CSS property. Can also invoke a callback to perform more specific processing tasks related to the property value. Please note that the return type is always an Array of strings. Each string corresponds to the CSS property value for the element with the same index in the xui collection.
x$( selector ).getStyle( property, callback );
String
is the name of the CSS property to get.Function
is called on each element in the collection and passed the property (optional). <ul id="nav">
<li class="trunk" style="font-size:12px;background-color:blue;">hi</li>
<li style="font-size:14px;">there</li>
</ul>
x$('ul#nav li.trunk').getStyle('font-size'); // returns ['12px']
x$('ul#nav li.trunk').getStyle('fontSize'); // returns ['12px']
x$('ul#nav li').getStyle('font-size'); // returns ['12px', '14px']
x$('ul#nav li.trunk').getStyle('backgroundColor', function(prop) {
alert(prop); // alerts 'blue'
});
Adds a class to all of the elements in the collection.
x$( selector ).addClass( className );
String
is the name of the CSS class to add.x$('.foo').addClass('awesome');
Checks if the class is on all elements in the xui collection.
x$( selector ).hasClass( className, fn );
String
is the name of the CSS class to find.fn Function
is a called for each element found and passed the element (optional).
// `element` is the HTMLElement that has the class
function(element) {
console.log(element);
}
<div id="foo" class="foo awesome"></div>
<div class="foo awesome"></div>
<div class="foo"></div>
// returns true
x$('#foo').hasClass('awesome');
// returns false (not all elements with class 'foo' have class 'awesome'),
// but the callback gets invoked with the elements that did match the 'awesome' class
x$('.foo').hasClass('awesome', function(element) {
console.log('Hey, I found: ' + element + ' with class "awesome"');
});
// returns true (all DIV elements have the 'foo' class)
x$('div').hasClass('foo');
Removes the specified class from all elements in the collection. If no class is specified, removes all classes from the collection.
x$( selector ).removeClass( className );
String
is the name of the CSS class to remove. If not specified, then removes all classes from the matched elements. (optional)x$('.foo').removeClass('awesome');
Removes the specified class if it exists on the elements in the xui collection, otherwise adds it.
x$( selector ).toggleClass( className );
String
is the name of the CSS class to toggle. <div class="foo awesome"></div>
x$('.foo').toggleClass('awesome'); // div above loses its awesome class.
Set multiple CSS properties at once.
x$( selector ).css( properties );
Object
is a JSON object that defines the property name/value pairs to set.x$('.foo').css({ backgroundColor:'blue', color:'white', border:'2px solid red' });