Obtain property values css

1

I would like to know how I can get values of the css styles, for example the color.

<style>
   .vermellet{color:red;}
</style>

<script>
  //.vermellet{color:red;}
  $(document).ready(function() {
    $("body").append("<a href='www.google.com'>google</a>");
</script>

</head>
<body>
  <p class="vermellet">Hola</p>
  <p>Adios</p>
  <p>Buenos dias</p>
</body>
</html>
    
asked by Oriol 19.11.2017 в 14:56
source

2 answers

0

Perfect, and if I wanted to add with the append to the end of everything in an unordered list, with class of?

$( "li" ).each(function() { 
alert(this); 
$("body").append("<div> "+this+" </div>");}

<ul class = naranja>
<li></li>
</ul>
    
answered by 19.11.2017 в 17:24
0

Since I see that you are using JQuery , you can refer to the element with that class and in this way obtain the value of its color by means of the css .

I also see a syntax error in your code and you need to close the function $(document).ready(function() { with }); .

Your modified example:

$(document).ready(function() {
  $("body").append("<a href='www.google.com'>google</a>");
  
  //Obtenemos el valor del color del elemento cuya clase es 'vermellet'
  console.log($(".vermellet").css("color"));
});
.vermellet{color:red;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="vermellet">Hola</p>
<p>Adios</p>
<p>Buenos dias</p>
    
answered by 19.11.2017 в 15:02