SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Threaded View

  1. #1
    SitePoint Addict Smola's Avatar
    Join Date
    Mar 2005
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Missing Attributes

    I have completed reading the Simply Javascript book from the authors of this site and have begun some exploration on my own. I am using the Core javascript file that came with the book for some basic functions. I have begin by simply creating some elements on an html page and using some javascript to reference them by class.

    the page:
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Java Testing</title>
    
    <script type="text/javascript" src="scripts/core.js">
    </script>
    
    <style type="text/css">
    
    .tab {
    	width:100px;
    	min-height:10px;
    	border:1px solid black;
    	background-color:#00CC00;
    	}
    	
    .button {
    	height:30px;
    	text-decoration:none;
    	color:#000000;
    	width:100%;
    	text-align:center;
    	}
    	
    </style>
    
    </head>
    
    <body>
    
    <div id="poop">
    
    	<div class="tab">
    		<a class="button">Click Me</a>
    	</div>
    	<div class="tab">
    		<a class="button">Click Me</a>
    	</div>
    
    </div>
    
    </body>
    </html>
    and the script:
    Code javascript:
    var changeHeight = {
     
    	init: function() {
     
    		var elements = Core.getElementsByClass("button");
     
    		for (var i = 0; i < elements.length; i++) {
    			var color = elements[i].textNode;
    			alert(color);
    		}
     
    	}
     
    }
     
    Core.start(changeHeight);

    The Core object references are functional and included in the script but not shown here. The function shown is the one I wrote simply to do some testing. I know that the getElementsByClass functions works because I get 2 alerts when I view the page. However, no matter what attribute I try to alert, I fail to get an accurate response.

    elements[i].style.height --> gave me a blank message box
    elements[i].style.color --> message box that said 'undefined'
    elements[i].textNode --> message box that said 'undefined'

    I am unsure why these attribute references aren't working, but I am sure it's a syntax issue on my part. Any ideas?



    Smola

    EDIT: By the way, the Core.start function was written in such a way that takes an object as input and ALWAYS executes the init function of the object.
    Last edited by Smola; May 21, 2008 at 10:54. Reason: Additional Info


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •