javascript - Add css properties to a collection from an object -


i need add css properties on each element of collection jquery. suggestions?

var jsoncss = {     "color": "#555555",     "font-weight": "bold",     "text-align": "left" };  var $tdcollection = $("tr:first-child").find("td:nth-child(2)"); //a collection of <td> elements $.each($tdcollection, function(k, v){     v.css(jsoncss); }) 

you don't need use each() here, can apply css settings elements within jquery object:

var cssobject = {     "color": "#555555",     "font-weight": "bold",     "text-align": "left" };  var $tdcollection = $("tr:first-child").find("td:nth-child(2)"); $tdcollecton.css(cssobject); 

also note object define holds css rules nothing json @ - it's object - hence why changed name.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -