开发者

Change colour of text based on a value of another div element, Jquery, html and css?

I want to change the color of a text, based on the value of another div elemen开发者_如何学运维t. I need this to run every second so setinterval has to go in there some where

something like this:

<div class="abcd">jkl</div>
<div class="xyz">7</div>
if("xyz" <10){
//change "abcd" to "abcd2" which changes its color}

I'm not good at Jquery but I think thats the tool needed for this job.


setInterval(function() { 
   var text = $(".xyz").text(); 
   if (parseFloat(text) < 10) {
      $(".abcd").addClass("abcd2").removeClass("abcd");
   }
   }, 1000); //run after every 1 second


$("document").ready(function() {
    var active = window.setInterval(function() {
        $(".abcd").css("backgroundColor",parseInt($(".xyz").text())<7?"#000":"#fff");
    }, 1000);
});

Does it work? Untested.

/e: Ouch, didn't read it that carefully. But I think you'll get the idea, and will be able to use addClass() and removeClass() like in the other answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜