Can the DOM be accessed through document.getElementID functions in the .js file. I had written about this in the previous post, but ...
This will help in removing the onclick attributes in the HTML tags.
Thanks
Sudhir
Dom javascript files
Yes the DOM can be accessed through document.getElementID functions in .js files
examples
Could yuo give an example?
I tried that but ended up with null errors. Morover there should be NO javascript in the HTML file, not even a onload clause. The script tag can put however.
So the initial code should be a procedural inline code in the .js file, i.e should not be a part of any function. Right ?
Thanks,
Sudhir
javascript questions.
Hi Astranomina,
If you put script tags within the head section or wish to call a function then you will need some event such as onload or onmouseover to call the JavaScript.
Here's a sample.
No, thats not what I meant.
Assume there is this .js file, which goes on like this:
var a;
var b;
document.onclick="dosomething()";
function dosomething()
{
......;
}
Now, my question is the 'document.onclick...' line executed WITHOUT any calls in the HTML file ? The HTML file will have nothing else other than the <script> element.
Is this possible. It is NOT within any function. So..., could you help me with that ?
Sudhir
event listeners
I think what you need to look into is event listeners.
Heres one method which seems to works in Netscape 6, and in IE >4
<html> <head> <script for="bdy" event="onclick" language="JavaScript" type="text/javascript" > var t="this sometimes works"; alert(t); </script> </head> <body id="bdy"> <h1>Simple test</h1> </body> </html>Hope that helps.