Reputation: 27909
//<![CDATA[
var blinkText = $(".highlight");
var interval = setInterval(function() {
blinkText.toggleClass("highlightRed");
}, 500);
//]]>
.highlight {
-webkit-transition: background 1.0s ease-in-out;
-ms-transition: background 1.0s ease-in-out;
transition: background 1.0s ease-in-out;
}
.highlightRed {
color: red !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<span class="highlight" style="font-weight: bolder; font-size: 33px; color: #00F">→</span>
The above code is expected to make the given arrow blink according to the interval given but it does not. How to make the arrow change colour with respect to the interval given?
Upvotes: 1
Views: 67
Reputation: 39392
You need to change following things to make your code work.
jQuery
to your web page.$(function() { ... });
code so that it founds elements in DOM
highlightRed
class should come after styles of .highlight
in stylesheet.Note: no need to use !important
in your styles. It should be avoided as much as possible.
$(function() {
var blinkText = $(".highlight");
var interval = setInterval(function () {
blinkText.toggleClass("highlightRed");
}, 500);
});
.highlight {
-webkit-transition: background 1.0s ease-in-out;
-ms-transition: background 1.0s ease-in-out;
transition: background 1.0s ease-in-out;
font-weight: bolder;
font-size: 33px;
color: #00F;
}
.highlightRed {
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<span class="highlight">→</span>
Upvotes: 2
Reputation: 8101
Just add !important in color:red:
.highlightRed {
color: red !important;
}
OR
IF you dont want to use !important, as !important id not a good practise just do it:
1) Remove inline css from span and add that style into any class called custom:
<span class="highlight custom">→</span>
.custom {
font-weight: bolder; font-size: 33px; color: #00F;
}
2) Define highlightRed css class like this:
span.highlightRed {
color: red;
}
Upvotes: 0