Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery changing style of HTML element

Tags:

html

jquery

css

People also ask

How do you change the style of an element using JQuery?

The css() method in JQuery is used to change the style property of the selected element. The css() in JQuery can be used in different ways. Return value: It will return the value of the property for the selected element.

Can we change CSS using JQuery?

You can change CSS using the jQuery css() method which is used for the purpose of getting or setting style properties of an element. Using this method you can apply multiple styles to an HTML all at once by manipulating CSS style properties.

Can JavaScript change the style of an HTML element?

The HTML DOM allows JavaScript to change the style of HTML elements.


Use this:

$('#navigation ul li').css('display', 'inline-block');

Also, as others have stated, if you want to make multiple css changes at once, that's when you would add the curly braces (for object notation), and it would look something like this (if you wanted to change, say, 'background-color' and 'position' in addition to 'display'):

$('#navigation ul li').css({'display': 'inline-block', 'background-color': '#fff', 'position': 'relative'}); //The specific CSS changes after the first one, are, of course, just examples.

$('#navigation ul li').css('display', 'inline-block');

not a colon, a comma


$('#navigation ul li').css({'display' : 'inline-block'});

It seems a typo there ...syntax mistake :))


you could also specify multiple style values like this

$('#navigation ul li').css({'display': 'inline-block','background-color': '#ff0000', 'color': '#ffffff'});