简体   繁体   中英

How do I apply a css class to certain elements using jquery?

I have a CSS-class RoundedActivityCell in my stylesheet, like this:

.RoundedActivityCell {
    -moz-border-radius: 4px 4px 4px 4px; /* rounds corners for firefox */ 
    border-radius:4px 4px 4px 4px; /* rounds corners for other browsers */
    float: left;
    text-align: center;
    vertical-align: middle;
    height: 18px;
    width: 150px; /* Follows the grid columns */
    border:solid 2px; 
    padding: 3px;
}

Then I have a span in my cshtml file, like this:

<span class="RoundedActivityCell" id="signalRAsxActivity-#:ViewUnitContract.ConveyanceId #">
    #: ViewUnitContract.Status.StatusText#
</span> 

I know how to apply certain css properties like border-color etc. using jquery, but I was wondering if it's possible to remove the class="RoundedActivityCell" part from the html tag and set that using jquery instead?

Ie (Never mind the conveyanceId part, it's automatically generated and works the way it's supposed to :) ):

$('#signalRAsxActivity-' + conveyanceId).css.class('RoundedActivityCell');

使用addClass

$('#signalRAsxActivity-' + conveyanceId).addClass("RoundedActivityCell")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM