And the winner isn't....">
Best IT Recipes

Change jQuery style of HTML element

I have a list in HTML

<div id="header" class="row"> <div id="logo" class="col_12">And the winner is<span>n't...</span></div> <div id="navigation" class="row"> <ul id="pirra"> <li><a href="#">Why?</a></li> <li><a href="#">Synopsis</a></li> <li><a href="#">Stills/Photos</a></li> <li><a href="#">Videos/clips</a></li> <li><a href="#">Quotes</a></li> <li><a href="#">Quiz</a></li> </ul> </div> 

it changes perfectly to show horizontal CSS change

  div#navigation ul li { display: inline-block; } 

but now I want to do this using jQuery, I use:

  $(document).ready(function() { console.log('hello'); $('#navigation ul li').css('display': 'inline-block'); }); 

but it doesn’t work, what am I doing wrong to style my element using jQuery?

thank

+92
jquery html css
manuelBetancurt Apr 18 '13 at 14:50 2013-04-18 14:50
source share
6 answers

Use this:

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

In addition, as others have already said, if you want to make several CSS changes at the same time, this is when you add curly brackets (to indicate an object), and it will look something like this (if you want 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. 
+200
VoidKing Apr 18 '13 at 14:51 2013-04-18 14:51
source share
 $('#navigation ul li').css('display', 'inline-block'); 

not a colon, comma

+19
Jakub Michálek Apr 18 '13 at 14:51 2013-04-18 14:51
source share
 $('#navigation ul li').css({'display' : 'inline-block'}); 

There seems to be a typo ... syntax error :))

+12
Suresh Atta Apr 18 '13 at 14:52 2013-04-18 14:52
source share

You can also specify multiple style values, such as

 $('#navigation ul li').css({'display': 'inline-block','background-color': '#ff0000', 'color': '#ffffff'}); 
+5
themis Sep 02 '13 at 8:43 2013-09-02 08:43
source share

I think you can use this code as well: and you can better manage your CSS class

 <style> .navigationClass{ display: inline-block; padding: 0px 0px 0px 6px; background-color: whitesmoke; border-radius: 2px; } </style> <div id="header" class="row"> <div id="logo" class="col_12">And the winner is<span>n't...</span></div> <div id="navigation" class="row"> <ul id="pirra"> <li><a href="#">Why?</a></li> <li><a href="#">Synopsis</a></li> <li><a href="#">Stills/Photos</a></li> <li><a href="#">Videos/clips</a></li> <li><a href="#">Quotes</a></li> <li><a href="#">Quiz</a></li> </ul> </div> <script> $(document).ready(function() { $('#navigation ul li').addClass('navigationClass'); //add class navigationClass to the #navigation . }); </script> 
+2
pedram shabani Aug 01 '17 at 10:00 2017-08-01 10:00
source share

style change using jquery

Try this

 $('#selector_id').css('display','none'); 

You can also change several attributes in one request

Try this

 $('#replace-div').css({'padding-top': '5px' , 'margin' : '10px'}); 
-one
Love Kumar Jul 05 '19 at 10:53 on 2019-07-05 10:53
source share


More articles:

  • Hibernation class exception - java
  • JQuery parameter set to switch using id and class switches - jquery
  • How to split Tamil characters in a string in PHP - php
  • How to choose element parent and siblings - jquery
  • HTTP API Examples HTTP Response Header Speed ​​Limit - http
  • java fill List with all enumeration values ​​- java
  • Install rootViewController from UINavigationController using a method other than initWithRootViewController - ios
  • Try again after the HTTP header response - does it affect anything? - http
  • When tracking variables in the console, how to create a new line? - javascript
  • TOMCAT - HTTP Status 404 - eclipse

All Articles

Geek Cook | 2019