|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
banner
Quote:
Last edited by Mittineague : February 16th, 2006 at 11:08 PM. |
|
#3
|
|||
|
|||
|
Code:
onLoad="hideads" should be Code:
onload="hideads();" though it would be better to not use the inline event handler. Code:
window.onload = hideads; |
|
#4
|
|||
|
|||
|
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?
|
|
#5
|
|||
|
|||
|
We would need to see an example of something that didn't work for you.
|
|
#6
|
||||
|
||||
|
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 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Document.getElementsByTagName() doesn't work. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|