Welcome Posted April 27, 2009 Share Posted April 27, 2009 When I try to style an image's cursor I get an undefined error. Here is the line of code causing the problem: document.images.style.cursor="pointer" I checked the cursor property to make sure I hadn't made a syntax error. But, according to the cursor propterty page ( http://www.w3schools.com/htmldom/prop_style_cursor.asp ) my syntax is correct (object.style.cursor="cursor"). In Firefox I get this error: "document.images.style is undefined." This works if I use "this.style.cursor='cursor'" inline, but not how I'm trying to do it. Here is the full code I'm using: <script type="text/javascript"> var x; for (x in document.images) { document.images.style.cursor="pointer"; } </script> In case you haven't realized the script is supposed to find all images and style the cursor. By the way, the script is in the body section. What am I doing wrong? Link to comment Share on other sites More sharing options...
Synook Posted April 27, 2009 Share Posted April 27, 2009 What you are doing is you are assigning each individual image to x, but then trying to apply the style to document.images without using x.Really, though, document.images is deprecated - document.getElementsByTagName is better. var images = document.getElementsByTagName("img");for (i = 0; i < images.length; i++) { images[i].style.cursor = "pointer";} Link to comment Share on other sites More sharing options...
Welcome Posted April 27, 2009 Author Share Posted April 27, 2009 Thanks for the help Synook. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.