jquery add style attribute to element code example

Example 1: jquery add style

//revising Ankur's answer
//Syntax:
$(selector).css({property-name:property-value});

//Example:
$('.bodytext').css({'color':'red'});

Example 2: jquery element css

//Set one style attribute
$('#element').css('display', 'block');
//Set multiple style attributes
$('#element').css({'display': 'block', 'background-color' : '#2ECC40'}); /* Multiple style *

Example 3: jquery modify style attribute

$('#yourElement').css('display', 'none');

Example 4: how to css in jquery

$(init);
    
function init() {
    $("h1").css("backgroundColor", "yellow");
    $("#myParagraph").css({ "backgroundColor": "black", "color": "white" });
    $(".bordered").css("border", "1px solid black");
}

Tags:

Css Example