Playing with CSS in jQuery – How to work with CSS in jQuery Explain?


How can we apply css to elements using JQuery library.
The below example is to apply css on div element that has id as DivId.
view sourceprint?
1.$(”#DivId “).css(”border”,”4px  red”);
To apply css in odd childs of parent node using JQuery library.
view sourceprint?
1.$(”tr:odd”).css(”background-color”, “#bbbbff”);
To apply css in even childs of parent node using JQuery library.
view sourceprint?
1.$(”tr:even”).css(”background-color”, “#bbbbff”);
To apply css in last child of parent using JQuery library.
view sourceprint?
1.$(”tr:last”).css({backgroundColor: ‘yellow’, fontWeight: ‘bolder’});
Now How can we modify css class using JQuery library?
Suppose that Css class has following definition
view sourceprint?
1..class
2.{
3.font-size:10px;
4.font-weight:normal;
5.color:#000000;
6.}
Now  if we are intrested to  add border property on above class, so we should follow below code.
view sourceprint?
1.$(“.class”).css(“border”,”1px solid blue”);
Where $(“.class”) name of css class. Now .class will automatically add border property in his class definition.
Happy jQuerying !!!!

0 comments:

Post a Comment