Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,333 members, 7,808,167 topics. Date: Thursday, 25 April 2024 at 08:00 AM

Why Is Javascript So Crappy - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Why Is Javascript So Crappy (1225 Views)

Free Html5, Css3, Javascript, Php And Mysql Ebooks. / Trouble With Javascript Code / Dhtml Quiz: How Will You Detect If A Browser Support Javascript From Php Code? (2) (3) (4)

(1) (Reply) (Go Down)

Why Is Javascript So Crappy by kambo(m): 7:41pm On Jun 10, 2006
angry
why is javascript so crappy, i've been trying for days to get this function to work

///: document.getElementById(String: id of element)
wont work. worked only once then it died.
tried : document.getElementByTagName(String);
wont even work, java dont act this crappy angry
ma learning is frozen ,cuz these are the only the ways i hope to access elements in the document(<body></body>wink body.
Re: Why Is Javascript So Crappy by kazey(m): 3:21am On Jun 11, 2006
define the main function withing the <head> tags and call the action within the body. Besides What are you trying to do?
Re: Why Is Javascript So Crappy by my2cents(m): 4:47am On Jun 11, 2006
Kambo,

I wdnt go as far as saying javascript is crappy, especially just because you can't get your code to work. If it were that "crappy", how come some pretty smart pple have been able to use it to create some pretty snazzy apps, courtesy of ajax? wink

Anyway, as kazey said, a better understanding of what you are trying to do, preferably with your entire code, is essential.

Looking at what you have so far, and I could be wrong, it begs the question:

What did you try to write? document.getElementById("element_name"wink or document.getElementById(element_name)?

If this is the case, and again I am pulling straws here, then the former would be right.

Give us some more rope please grin
Re: Why Is Javascript So Crappy by Zahymaka(m): 4:51am On Jun 11, 2006
document.getElementById was introduced with the DOM 2.0 specification so some old browsers do not support it. All browsers from version 6 and above [Opera, IE and NS], then all versions of Firefox support it.

Could you tell us what exactly you're trying to do -- perhaps giving us both the HTML and Javascript code? You could get into some trouble if, as Kazey pointed out, you tried to retreive an object that hasn't been loaded into the DOM tree ie before the page has finished loading.
Re: Why Is Javascript So Crappy by kambo(m): 2:53pm On Jun 15, 2006
actually i was hoping to gain a lil grasp of javascript b4 the month is up- i'm learning.
but when it comes to this function everything i do freezes ,things just dont work.
and i dont know any other way to manipulate elements in the document.
worst news is that the author of the book i'm using("professional javascript, ",wrox press)makes extensive use of this javascript functions to access the dom tree , feel like strangling javascript,i'm stuck in ma learning .
////////////
sample code is\
//just to see if javascript can 'feel' the html tags

<html>
<head>
<script ="javascript">




var a = document.getElementById("hech1"wink;
var b = document.getElementById("para"wink;

// if it 's not null the identify the tag
if(b!= null){status = b.tagName;}//nothing shows in the status panel sad

// i try
if(a == null){ alert("element is null"wink;} //alert window pops up with glee.!!




alert( b==null)
// outputs "true"
?? why.
i try document.getElementByTagName(String);\ i.e "h1" or "p"
output is still null
</script></head>
<body >
<h1 id="hech1"> this java script wahala</h1><br>
<p id="para"> how do i access the dom tree elements</p>

</body>
</html>
Re: Why Is Javascript So Crappy by Zahymaka(m): 3:41pm On Jun 15, 2006
Now, you have the right idea. I'm sorry Javascript is giving you such a tough time. The problem is you're trying to access the DOM Nodes before they're loaded:

Let's modify your code to:

<html>
<head>
<script ="javascript">
window.onload = function(){
var a = document.getElementById("hech1"wink;
var b = document.getElementById("para"wink;
// if it 's not null the identify the tag
if(b!= null){status = b.tagName;}//nothing shows in the status panel
if(a == null){ alert("element is null"wink;} //alert window pops up with glee.!! Huh
alert( b==null)
}
</script></head>
<body >
<h1 id="hech1"> this java script wahala</h1><br>
<p id="para"> how do i access the dom tree elements</p>

</body>
</html>


Hopefully, this should work for you - I tested it myself. When trying to get an element, ensure you do so after the page has finished loading. I hope this helps.

(1) (Reply)

Web Designers Needed / Problems Faced By Young Web Entrepreneurs In Africa Below 30yrs / Why I Can't Read The News On Www.nigeria.gov.ng

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 19
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.