JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 16th, 2006, 10:37 PM
Akdor 1154 Akdor 1154 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Center Canyon in a Raptor
Posts: 34 Akdor 1154 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 44 sec
Reputation Power: 14
Document.getElementsByTagName() doesn't work.

Hi,

Just trying to hide an ad on my page - it's put there by a serverside script; it'll always be the first <div> on the page. Because it has a randomly generated ID, I'm using document.getElementsByTagName("div")[0]. But it doesn't work.

Using Firefox's JavaScript console, document.getElementsByTagNames("div").length returns 0. So does "table", "span", and anything else. The only tags I've found that DO return something are html, head, and body - they all return 1. Any ideas?

The page in question is at http://akdor.freeownhost.com/primes.php

Reply With Quote
  #2  
Old February 17th, 2006, 12:05 AM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 552 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 1 m 33 sec
Reputation Power: 13
banner

Quote:
11. BANNER - Each free account has one small banner with text links. Any attempt to remove, hide and/or block the banner without our explicit permission will automatically result in closing the corresponding hosting account.
Contact the people you got permission from and ask them what's up. They should be able to help you get rid of it.

Last edited by Mittineague : February 17th, 2006 at 12:08 AM.

Reply With Quote
  #3  
Old February 18th, 2006, 11:23 PM
Kravvitz Kravvitz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Location: USA
Posts: 140 Kravvitz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 33 m 14 sec
Reputation Power: 13
Code:
onLoad="hideads"

should be
Code:
onload="hideads();"

though it would be better to not use the inline event handler.
Code:
window.onload = hideads;

Reply With Quote
  #4  
Old April 4th, 2006, 01:08 AM
Akdor 1154 Akdor 1154 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Center Canyon in a Raptor
Posts: 34 Akdor 1154 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 44 sec
Reputation Power: 14
Well I've given up hiding ads, it's not really achieving anything... but that doesn't mean I can get document.getElementsByTagName() to work. Same problem as before, the only parameters that will return something are 'html', 'body', and 'head'. Everything else returns an array of length 0. document.body.getElementsByTagName() doens't work, either. Ideas?

Reply With Quote
  #5  
Old April 4th, 2006, 11:03 AM
Kravvitz Kravvitz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Location: USA
Posts: 140 Kravvitz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 33 m 14 sec
Reputation Power: 13
We would need to see an example of something that didn't work for you.

Reply With Quote
  #6  
Old April 4th, 2006, 12:45 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 18
I had a peek at the URL you posted above... it looks like you're still trying your hideads, which I won't bitch about, but I did notice a potential error that I will paraphrase into my own example...
Code:
<script>
function loading() {
    alert ('hello');
}
</script>

</head>

<body onload="loading">

The browser isn't going to call that onload method without the brackets... try onload="loading()" instead.

Try this script below... I've been playing with it and it seems to work locally.
Try it locally and try it on the server... see if you get different results.
I predict you're using getElementsByTagName incorrectly.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Department Store</title>

<script>
function domTests() {
	mylist = document.getElementsByTagName('ul');
	mylist.item(2).style.backgroundColor = '#f00';
}
</script>

</head>

<body onload="domTests()">

<h1>Department Store</h1>

<ul class="elevator">
	<li><a href="#" class="door">Basement</a>
		<ul>
			<li>Parking</li>
			<li>Clearance Items</li>
		</ul>
	</li>
	<li><a href="#">1st Floor</a>
		<ul>
			<li>Frozen Food</li>
			<li>Bakery</li>
			<li>Deli</li>
		</ul>
	</li>
	<li><a href="#">2nd Floor</a>
		<ul>
			<li>Men's clothing</li>
			<li>Entertainment Centres</li>
			<li>Children's clothing</li>
			<li>Hardware</li>
			<li>Toys</li>
		</ul>
	</li>
	<li><a href="#">3rd Floor</a>
		<ul>
			<li>Women's shoes</li>
			<li>Jewerly</li>
		</ul>
	</li>
	<li><a href="#">4th Floor</a>
		<ul>
			<li>Media</li>
			<li>Lingerie</li>
		</ul>
	</li>
</ul>

</body>
</html>
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter!
DevArticles Forum Moderator

"The net is a waste of time, and that's exactly what's right about it." -- William Gibson

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Document.getElementsByTagName() doesn't work.


Developer Shed Advertisers and Affiliates


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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap