Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old April 3rd, 2005, 09:14 AM
MikePB MikePB is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Oak Creek Wi, USA
Posts: 5 MikePB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to MikePB Send a message via AIM to MikePB Send a message via Yahoo to MikePB
problem with JS functions

Hi, I'm having trouble getting these two functions to work:

Code:
function getLikeElements(tagName, attrName, attrValue){
		var startSet;
		var endSet = new Array( );
		if (tagName){
			startSet = document.getElementsByTagName(tagName);    
		} else {
			startSet = (document.all) ? document.all : 
            document.getElementsByTagName("*");
		}
		if (attrName){
			for (var i = 0; i < startSet.length; i++) {
				if (startSet[i].getAttribute(attrName)) {
					if (attrValue) {
						if (startSet[i].getAttribute(attrName) == attrValue) {
							endSet[endSet.length] = startSet[i];
						}
					} else {
						 endSet[endSet.length] = startSet[i];
					}
				}
			}
		} else {
			endSet = startSet;
		}
		return endSet;
	}


	function getElementPosition(elemID)
	{
		var offsetTrail = document.getElementById(elemID);
		var offsetLeft = 0;
		var offsetTop = 0;
		while (offsetTrail)
		{
			offsetLeft += offsetTrail.offsetLeft;
			offsetTop += offsetTrail.offsetTop;
			offsetTrail = offsetTrail.offsetParent;
		}
		if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined")
		{
			offsetLeft += document.body.leftMargin;
			offsetTop += document.body.topMargin;
		}
		return {left:offsetLeft, top:offsetTop};
	}


Two examples return as [object HTMLImageElement] and [object Object] respectively...

disclaimer: I typed these in from an O'Rielly Book, but I *would* like to get them to work, as they will work well is getting posisioning elements for a small web RPG I'm working on.


Thanks!

Mike

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > problem with JS functions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT