Click here to Skip to main content
15,885,949 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

how can modify css class property by using jqury?

I have css class,

CSS
.slider-content
            {
                padding-left: 0px !important;
                left: 10%;
                right: 10%;
                top: 125px;
                height: 50px !important;
                width:100% !important;
            }


I want to modify this css class using jquery event

Thanks.
Posted

You can't modify the class itself but you can change the css properties of all the elements that have that class.

JavaScript
$(".slider-content").each(function(){
    $(this).css("padding-left", "10px"); //do this for each property you want to change.
});
 
Share this answer
 
Comments
ExpertITM 21-Feb-13 13:41pm    
hi,

this will effect only one property(padding-left)? Or remove all other property from class?

Thanks.
Shelby Robertson 21-Feb-13 14:10pm    
It will only modify that property. All other properties remain the same.
You can't modify or change the class properties. Instead u can overwrite its property. See below examples..
This is your css class..
CSS
.slider-content
  {
    padding-left: 0px !important;
    left: 10%;
    right: 10%;
    top: 125px;
    height: 50px !important;
    width:100% !important;
  }

JQuery code below..

JavaScript
$(".slider-content").css("padding-left", "10px"); 
means you are overwriting only 'padding-left' property of slider-content class. So only padding-left property will change, Remaining properties will not change.

To overwrite multiple properties at a time code below..
C#
$('.slider-content').css({'width' : '900px','height' : '50px'});

hope it helps you lot..
 
Share this answer
 
$('#elem').css({
width : '100px',
height : '50px'
});

$('.slider-content').css({
width : '900px',
height : '50px'
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900