0
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.js"></script>
<style type="text/css">
body
{
color:green;
}
</style>
<script type="text/javascript">
$(document).ready(function()
{
 setInterval(findYellow,1000);    
 function findYellow()
{
  $("ul").each(function()
{
   var $this = $(this);
   if($this.css("color") != "green")
{
    $this.css("color", "green");
   $this.text("abcd blue");
   }
else
{
    $this.css("color", "blue");
     $this.text("abcd green");
   }
  });
 }

});
</script>
</head>



    <body>
        <ul>This is a sample set
            <li>1</li>
            <li>3</li>
            <li>5</li>
            <li>7</li>
            <li>9</li>
        </ul>

    </body>
</html>
Chandu
  • 81,493
  • 19
  • 133
  • 134
abc
  • 1

3 Answers3

1

Here's a way to do it without JQuery

HTML:

<ul>
  <li id='one' style='display:none'>One</li>
  <li id='two' style='display:none'>Two</li>
</ul>

Javascript:

function showOne() {
  document.getElementById('one').style.display = '';
}

function showTwo() {
  document.getElementById('two').style.display = '';
}

setTimeout(showOne,1000);
setTimeout(showTwo,2000);

You can also get list elements by their index, using the .childNodes[] array property of any <ul> object.

Ben
  • 54,723
  • 49
  • 178
  • 224
0

Use

$("li")

instead of

$("ul").
jd.
  • 4,057
  • 7
  • 37
  • 45
0

If you want to change the colors of li independently then use $("ul li") instead of $("ul"), this iterate through each li elements under the ul element.

I think there are more problems with your code $().css("color") returns RGB value instead of the color green so you if condition will always fail.

Use the method provided in this post to convert the rgb value to hex value and then compare the values.

Check a working solution in this fiddle.

Need more information about the li in same interval portion of the question.

Community
  • 1
  • 1
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531