1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Changing <Div> Content after time period

Discussion in 'HTML & Website Design' started by tobywuk, Mar 29, 2008.

  1. #1
    On news and big website home pages, sometimes you get blocks of text, such as news, that changes to different content after a period of time, say 10 seconds.

    Im just wondering how to change the contet of a <Div> to do this? Im guessing its a java script technique. I have never really written java script though I can code Java.

    thanks
    SEMrush
     
    tobywuk, Mar 29, 2008 IP
    SEMrush
  2. Morishani

    Morishani Peon

    Messages:
    239
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Done it for you :
    <script type="text/javascript">
    function initChangeText()
    	{
    	var time = 10;
    	setInterval('changeText();',time*1000);
    	}
    function changeText()
    	{
    	var divs_ = document.getElementsByTagName("div")
    	for (var i = 0;i<divs_.length;i++)
    		if (divs_[i].className == "change")
    			changeULText(divs_[i]);
    
    	}
    function changeULText(obj)
    	{
    	var ul = obj.getElementsByTagName("ul")[0];
    	var li = obj.getElementsByTagName("li");
    	for (var i=0;i<li.length;i++)
    		{
    		if (li[i].className == "show")
    			{
    			li[i].className = "";
    			li[(i+1)%li.length].className = "show";
    			return ;
    			}
    		}
    	}
    window.onload = initChangeText;
    </script>
    HTML:
    This is preety much the script, and with CSS and HTML it looks like this (see attached file)
     

    Attached Files:

    Morishani, Mar 29, 2008 IP
  3. HDaddy

    HDaddy Active Member

    Messages:
    287
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Hey this is great! Can i use it too?
     
    HDaddy, Mar 29, 2008 IP
  4. Morishani

    Morishani Peon

    Messages:
    239
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sure, It's free for anybody :)
     
    Morishani, Mar 29, 2008 IP
    Scorpiono likes this.
  5. Scorpiono

    Scorpiono Well-Known Member

    Messages:
    1,330
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    120
    #5
    Morishani, nice of you, I'm green repping anyway
     
    Scorpiono, Mar 29, 2008 IP