Author Topic: document.getElementByClassName Not working  (Read 206 times)

Baby_Bean

  • Regular Member
  • **
  • Posts: 40
  • Karma: 0
    • View Profile
Hi everyone
Attached is my code where I want background image of a div to be selected by js:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  
  <!DOCTYPE html>
  
  <html lang = "en">
  <head>
    <title>to-forum.html</title>
    <meta charset="utf-8" />
    <style>
    .logo
   {
     width:1200px;
     height:300px;
     margin:auto;
     display: block;
     background-repeat:no-repeat;
     position:relative;
     border-radius: 25px;
   }
   </style>
     <script>
       function ChangeImage(param)
       {
         switch(param)
         {
           case '1':
             return("images/greensilver.gif");
             break;
           case'2':
             return("images/greensilver1.gif");
             break;
         }
       }
     </script>
 </head>
 
 <body>
   <div id="logo">
     <script>
       document.getElementByClassName("logo").style.backgroundImage = "url('" + ChangeImage('1') + "')";
     </script>
   </div>
 </body>
 </html>
 
The image dont show ! Can you help me the code?

PHP Help Forum

document.getElementByClassName Not working
« on: July 03, 2017, 06:40:45 am »



PHP Help Forum

Re: document.getElementByClassName Not working
« Reply #1 on: July 03, 2017, 01:57:25 pm »



PHP Help Forum

Re: document.getElementByClassName Not working
« Reply #2 on: September 03, 2017, 03:45:24 pm »