Avhelsing
Avhelsing

Reputation: 81

Select Properties From CSS Class

There is a way to select properties of a css class using Jquery?

example_class{
color: red;
font-size: 30px;
}

<span id="span1" class="example_class">Hello World!</span>
<span id="span2">Second Span</span>

What I actually need to do is get the color property of span1 and aply to span2.

Upvotes: 0

Views: 71

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1075765

What I actually need to do is get the color property of span1 and aply to span2.

jQuery's css gets the computed value of a property, and (when used as a setter) sets it on the element, so:

$("#span2").css("color", $("#span1").css("color"));

Example:

$("#span2").css("color", $("#span1").css("color"));
.example_class {
  color: red;
  font-size: 30px;
}
<span id="span1" class="example_class">Hello World!</span>
<span id="span2">Second Span</span>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Upvotes: 3

Related Questions