dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: background of text

  1. #1
    Join Date
    Oct 2017
    Posts
    18

    background of text

    With out using no attributes , how can i write the below code to change the background of the text every second.
    Also any other code( for beginners in JS) with out using i = (i + 1) % color.length;

    Thank You..

    Code:
    <!DOCTYPE html>
    <html>
    <body>
    <p id ="test"> Welcome to JAvaScript</p>
    <script type="text/javascript">
    
    var i = 0;
    function change() {
      var doc = document.getElementById("test");
      var color = ["red", "white", "blue","black","orange","green"];
      doc.style.color = "black";
      doc.style.backgroundColor = color[i];
    
    if(i == 3)
      {
    
      doc.style.color = "white";
      doc.style.fontFamily = "Arial";
      doc.style.fontSize = "larger";
    
        }
    
      i = (i + 1) % color.length;
      
      
    }
    
    setInterval(change, 1000);
    
    
     
    
    </script>
    </body>
    </html>

  2. #2
    Join Date
    Oct 2013
    Location
    Sheboygan, Wisconsin
    Posts
    1,615
    change the background of the text every second.
    Run off the visitors most likely. I would leave real quickly.

  3. #3
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,535
    > With out using no attributes

    As in without doc.style? I suppose you could set class names instead of styles... but that still amounts to setting attributes. So... I suppose the answer is no. You're going to have to set an attribute in one form or another. And that's fine and normal.

    > Also any other code( for beginners in JS) with out using i = (i + 1) % color.length;

    Beginner or not, that's a normal and correct way to cycle a number through a range.
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  4. #4
    Join Date
    Oct 2017
    Posts
    18
    What's wrong with this code??? .. Its showing error .


    Code:
    <!DOCTYPE html>
    <html>
    <body>
    
    <script type="text/javascript">
    
    var i = 0;
    function change() {
      
    var doc = "Welcome to Javascript";
    
      var color = ["red", "white", "blue","black","orange","green"];
      doc.style.color = "black";
      doc.style.backgroundColor = color[i];
    
    if(i == 3)
      {
    
      doc.style.color = "white";
      doc.style.fontFamily = "Arial";
      doc.style.fontSize = "larger";
    
        }
    
      i = (i + 1) % color.length;
      
      
    }
    
    setInterval(change, 1000);
    
    
     
    
    </script>
    </body>
    </html>

  5. #5
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,535
    You replaced your dom element with a plain string but still tried to access dom attributes such as style.
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  6. #6
    Join Date
    Oct 2017
    Posts
    18
    Thank You..

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center