javascript - jQuery stops working when quotes removed from a property in css method -


in jquery docs, mentioned quotes optional in code when remove it, error flags in firebug console.

also, jquery can equally interpret css , dom formatting of multiple-word properties. example, jquery understands , returns correct value both .css({'background-color': '#ffe', 'border-left': '5px solid #ccc'}) , .css({backgroundcolor: '#ffe', borderleft: '5px solid #ccc'}). notice dom notation, quotation marks around property names optional, css notation they're required due hyphen in name.

reference link: http://api.jquery.com/css/#css-propertyname-value

let me know doing wrong concept , ways of using property/value pair in css method?

whole code -

<!doctype html> <html>     <head>         <title>jquery css check</title>         <style>         li {color:red;}         </style>     </head>     <body>         <ul>             <li>product 1</li>             <li>product 2</li>         </ul>         <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>         <script>         jquery(document).ready(function(){         jquery('li').css({color:'green',font-size:'18px'});         });         </script>        </body> </html> 

error in firebug console: syntaxerror: missing : after property id

ya; quotes optionnal not properties wich contains '-' character. so, have use quotes wrap kind of properties:

jquery('li').css({color:'green','font-size':'18px'}); 

as yoshi pointed it, can use camelcase synthax property too:

jquery('li').css({color:'green',fontsize:'18px'}); 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -