Jump to content

On Events Inside Js?


MrFish

Recommended Posts

Although I loved using JQuery I think I need to stay away from these helper files. It's simply not very professional if you ask me. One thing I've liked the most about jquery was that you can create onmouse events inside the script. This makes it much simpler and organised. I've tried googling a way to do this with js but I'm having trouble finding a working method. Here is what I've come up with-

document.getElementById("test").onmousemove = function(e){	var evt=document.event || e;	document.getElementById("test").innerHTML=evt.clientX+" : "+evt.clientY;}

the html

<div id="test">Box 1</div><div>Box 2</div>

It works if I take out the "getElementById('test')" but with it in there I get this error message in Chrome JS Console-

Uncaught TypeError: Cannot set property 'onmousemove' of null
I've never liked js and I think it's the weakest part of my game (so to speak). Any help would be excellent!
Link to comment
Share on other sites

This just means that the element with an ID called "test" doesn't exist. It probably is because you're trying to access it before it's created.
Thanks! window.onload did the trick :)
Link to comment
Share on other sites

I think people should learn Javascript thoroughly before relying on libraries like jQuery. The reason being that then you are able to understand what's going on and what jQuery is doing.

Link to comment
Share on other sites

I am personally a JavaScript purist. But that is because I am in a position where I can pick and choose my assignments. I agree with Ingolme about learning JS and the DOM API thoroughly before moving on to the big libraries, like jQuery. Nothing beats understanding, and if you don't know what jQuery is doing for you, it may be hard to understand a problem when it comes up.So I think MrFish is making a good choice for right now.But be aware that A LOT of corporate sites and developers are incorporating those libraries into their projects because they do a lot of good stuff and speed up development time. So I wouldn't be so fast to make a distinction between professional and not-professional. In fact, knowing jQuery and 1-2 other libraries IN ADDITION TO your other knowledge could mean the difference between getting a job and not getting a job. Same is true even of things like WordPress, which a lot of developers are now using as a platform for entire sites.

Link to comment
Share on other sites

Knowing how to use a framework may also mean the difference between getting the job done on time, or several weeks late :)Knowing pure JavaScript is crucial to understanding the way things work at a low level, but when getting jobs done in a professional environment, where consistency, maintainability, and speed are more important than, well, purity or the technical demonstration of knowledge for the sake of it, frameworks help a lot.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...