jQuery css() get style property value

Introduction

The following code shows how to use css() to get style property value.

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>//from   w ww .j  av a  2  s .c o m
<script>
$(document).ready(function(){
  $("button").click(function(){
    document.getElementById("demo").innerHTML = $("p").css("color");
  });
});
</script>
</head>
<body>

<p id="demo"></p>
<button>Return CSS color value of p element</button>

<p style="color:red">This is a paragraph.</p>

</body>
</html>



PreviousNext

Related