Results 1 to 3 of 3

Thread: If body id = xx then

  1. #1
    Join Date
    Mar 2013

    Question If body id = xx then

    Hi there!

    I am really really new in Javascript. I am a noob

    I want to integrate a slideshow in my site. In the Javascript is a variable for the images array.
    the only thing i want to do is:
    if the body id is HOME, then the variable should have image1 and image2 for example.
    if the body id is TEST, then the variable should have image3 and image4 for example.

    First question is, if i use the "document.getElementsByTagName('body')[0];" in this script,
    must i include the xxx.js script in the html document IN the body to get it work?
    I also tried this, but it wasn't working

    my html code:
    <script type="text/javascript" src="be_slide.js"></script>
    	<body id="test">
    			<div id="slideshow" style="margin-left:15px;margin-top:15px;width:200px;height:200px;">
    			<img src="pics/pic01a.jpg" style="width:200px;height:200px;" />
    The Javascript Code i tried:
    var theBody = document.getElementsByTagName('body')[0];
    if(theBody === 'test'){
    	 var def_imges=new Array ('Maske.jpg', 'Maske2.jpg', 'Maske3.jpg');
    could you please help me? :/
    thank you very very much!

  2. #2
    Join Date
    Jul 2008
    urbana, il
    put the script just before </body>

    also, check the ID, not the tag itself:

    var theBody = document.getElementsByTagName('body')[0].id;
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

  3. #3
    Join Date
    Mar 2013
    oh, you are my hero!

    it works!!!!! Thank you very much!

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