Reputation: 81
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
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