Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. onmouseover and document.getElementById

onmouseover and document.getElementById

Scheduled Pinned Locked Moved JavaScript
helphtmldatabasetoolsquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SRJ92
    wrote on last edited by
    #1

    Hi! This has been bugging me for quite a while now... I have done many google searches but nothing seems to actually help me.... When i run this script i get the following error: "SCRIPT5007: Unable to set value of the property 'onmouseover': object is null or undefined" I don't know how it doesn't work but if i use onmouseover="show()" and obviosuly remake my function heading it works... I can't use the onmouseover="" as apparently its not the best way of doing it... Cna nayone shine some light on where it could be going wrong? Thanks for all your help!

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    		#gallery
    			{
    				position:relative;
    				display:block;
    				width:800px;
    				height:500px;
    				margin:20px auto;
    				text-align:center;
    			}
    		#image
    			{
    				display:block;
    				width:800px;
    				height:500px;
    			}
    		#imgBar
    			{
    				position:absolute;
    				display:block;
    				width:500px;
    				height:80px;
    				z-index:2;
    				top:400px;
    				left:145px;
    				display:none;
    			}		
    	
    	<script>
    		var galleryImg = document.getElementById('image');
    		var bar = document.getElementById('imgBar');
    		
    		galleryImg.onmouseover = function ()
    		{
    			bar.style.display = "block";
    		};
    		galleryImg.onmouseout = function ()
    		{
    			bar.style.display = "none";
    		};
    	</script>
    </head>
    <body>
    
    
    	![](#)
    	
    
    	![](img/gallery/thumbnail1.png)
    	![](img/gallery/thumbnail1.png)
    	![](img/gallery/thumbnail1.png)
    	![](img/gallery/thumbnail1.png)
    	
    
    
    
    </body>
    

    </html>

    J S 2 Replies Last reply
    0
    • S SRJ92

      Hi! This has been bugging me for quite a while now... I have done many google searches but nothing seems to actually help me.... When i run this script i get the following error: "SCRIPT5007: Unable to set value of the property 'onmouseover': object is null or undefined" I don't know how it doesn't work but if i use onmouseover="show()" and obviosuly remake my function heading it works... I can't use the onmouseover="" as apparently its not the best way of doing it... Cna nayone shine some light on where it could be going wrong? Thanks for all your help!

      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

      		#gallery
      			{
      				position:relative;
      				display:block;
      				width:800px;
      				height:500px;
      				margin:20px auto;
      				text-align:center;
      			}
      		#image
      			{
      				display:block;
      				width:800px;
      				height:500px;
      			}
      		#imgBar
      			{
      				position:absolute;
      				display:block;
      				width:500px;
      				height:80px;
      				z-index:2;
      				top:400px;
      				left:145px;
      				display:none;
      			}		
      	
      	<script>
      		var galleryImg = document.getElementById('image');
      		var bar = document.getElementById('imgBar');
      		
      		galleryImg.onmouseover = function ()
      		{
      			bar.style.display = "block";
      		};
      		galleryImg.onmouseout = function ()
      		{
      			bar.style.display = "none";
      		};
      	</script>
      </head>
      <body>
      
      
      	![](#)
      	
      
      	![](img/gallery/thumbnail1.png)
      	![](img/gallery/thumbnail1.png)
      	![](img/gallery/thumbnail1.png)
      	![](img/gallery/thumbnail1.png)
      	
      
      
      
      </body>
      

      </html>

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      An HTML page is interpreted top to bottom. When your javascript runs (in the head) the HTML has not yet been parsed, and therefore does not exist. Put everythng into a function

      function runMeOnLoad(){
      var galleryImg = document.getElementById('image');
      var bar = document.getElementById('imgBar');

      galleryImg.onmouseover = function ()
      {
          bar.style.display = "block";
      };
      galleryImg.onmouseout = function ()
      {
          bar.style.display = "none";
      };
      

      }

      And execute onload

      S 1 Reply Last reply
      0
      • J J4amieC

        An HTML page is interpreted top to bottom. When your javascript runs (in the head) the HTML has not yet been parsed, and therefore does not exist. Put everythng into a function

        function runMeOnLoad(){
        var galleryImg = document.getElementById('image');
        var bar = document.getElementById('imgBar');

        galleryImg.onmouseover = function ()
        {
            bar.style.display = "block";
        };
        galleryImg.onmouseout = function ()
        {
            bar.style.display = "none";
        };
        

        }

        And execute onload

        S Offline
        S Offline
        SRJ92
        wrote on last edited by
        #3

        Brilliant, thank you :)

        1 Reply Last reply
        0
        • S SRJ92

          Hi! This has been bugging me for quite a while now... I have done many google searches but nothing seems to actually help me.... When i run this script i get the following error: "SCRIPT5007: Unable to set value of the property 'onmouseover': object is null or undefined" I don't know how it doesn't work but if i use onmouseover="show()" and obviosuly remake my function heading it works... I can't use the onmouseover="" as apparently its not the best way of doing it... Cna nayone shine some light on where it could be going wrong? Thanks for all your help!

          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

          		#gallery
          			{
          				position:relative;
          				display:block;
          				width:800px;
          				height:500px;
          				margin:20px auto;
          				text-align:center;
          			}
          		#image
          			{
          				display:block;
          				width:800px;
          				height:500px;
          			}
          		#imgBar
          			{
          				position:absolute;
          				display:block;
          				width:500px;
          				height:80px;
          				z-index:2;
          				top:400px;
          				left:145px;
          				display:none;
          			}		
          	
          	<script>
          		var galleryImg = document.getElementById('image');
          		var bar = document.getElementById('imgBar');
          		
          		galleryImg.onmouseover = function ()
          		{
          			bar.style.display = "block";
          		};
          		galleryImg.onmouseout = function ()
          		{
          			bar.style.display = "none";
          		};
          	</script>
          </head>
          <body>
          
          
          	![](#)
          	
          
          	![](img/gallery/thumbnail1.png)
          	![](img/gallery/thumbnail1.png)
          	![](img/gallery/thumbnail1.png)
          	![](img/gallery/thumbnail1.png)
          	
          
          
          
          </body>
          

          </html>

          S Offline
          S Offline
          sachin_jain
          wrote on last edited by
          #4

          Put your script code where the "section" tag ends (before the body tag ends) and it'll work fine.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups