Answers for "jquery get style attribute of element"

4

jquery set style property

$("selector").css("property", "value");

// Example:
$("div").css("background-color", "red");
Posted by: Guest on October-01-2020
8

jquery element css

//Set one style attribute
$('#element').css('display', 'block');
//Set multiple style attributes
$('#element').css({'display': 'block', 'background-color' : '#2ECC40'}); /* Multiple style *
Posted by: Guest on June-05-2020
1

get css value jquery

var font-size = $('p').css('font-size');
console.log(font-size);
Posted by: Guest on October-18-2020
1

styling element using jquery

Syntax:
$(selector).css(property-name:property-value);

Example:
$('.bodytext').css('color':'red');
Posted by: Guest on June-01-2020
0

jQuery inline element style get set

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>css demo</title>
  <style>
  div {
    height: 50px;
    margin: 5px;
    padding: 5px;
    float: left;
  }
  #box1 {
    width: 50px;
    color: yellow;
    background-color: blue;
  }
  #box2 {
    width: 80px;
    color: rgb(255, 255, 255);
    background-color: rgb(15, 99, 30);
  }
  #box3 {
    width: 40px;
    color: #fcc;
    background-color: #123456;
  }
  #box4 {
    width: 70px;
    background-color: #f11;
  }
  </style>
  <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
 
<p id="result"> </p>
<div id="box1">1</div>
<div id="box2">2</div>
<div id="box3">3</div>
<div id="box4">4</div>
 
<script>
$( "div" ).click(function() {
  var html = [ "The clicked div has the following styles:" ];
 
  var styleProps = $( this ).css([
    "width", "height", "color", "background-color"
  ]);
  $.each( styleProps, function( prop, value ) {
    html.push( prop + ": " + value );
  });
 
  $( "#result" ).html( html.join( "<br>" ) );
});
</script>
 
</body>
</html>
Posted by: Guest on July-31-2020

Code answers related to "jquery get style attribute of element"

Code answers related to "Javascript"

Browse Popular Code Answers by Language