jQuery .css()

jQuery .css() gets or sets the css style property for the target element;

<script>
$('.target').css('background-color', 'yellow').append(' <span class="label label-info">set background-color</span>');
 
$('.target2').css({
    'background-color': 'yellow',
    'font-weight': 'bold'
}).append(' <span class="label label-info">set background-color and font-weight</span>');
 
$('.target3').append(' bg-color:' + $('.target3').css('background-color')).append(' <span class="label label-info">get background-color</span>');</script>
<div class="well">
<span class="target">.target</span>
</div>
 
<div class="well">
<span class="target2">.target2</span>
</div>
 
<div class="well">
<span class="target3">.target3</span>
</div>
.target3 {
    background-color: #afa;
}

Leave a Reply

Your email address will not be published. Required fields are marked *