Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get css property from class using jquery [closed]

How can i get the 'color' property from test class but should not use .addClass and .css function.

.test {
  color: red;
  margin: 10px 10px 10px 10px;
}

I need to add color property for other class.something like following

<div class="getproperty"></div>

How can i get only color property from test class to use getproperty class.

Update :

I want to get the color property that is for the class:test and to use the obtained color to another class named as getproperty.

How can i do this in jquery ?

like image 340
Deenadhayalan Manoharan Avatar asked Sep 29 '22 17:09

Deenadhayalan Manoharan


2 Answers

With jQuery you could do something like this:

var color = $("<i>", {class: "test"}).css("color");
$(".getproperty").css("color", color);

This doesn't require you have an element with the class test in the page

like image 64
winhowes Avatar answered Oct 03 '22 10:10

winhowes


If you want to get the color from the class:

var color = $(".test").css("color");
$(".getproperty").css("color", color);
like image 40
Michael Dziedzic Avatar answered Oct 03 '22 11:10

Michael Dziedzic