3 ms·
Just a quick note of caution: id attributes are supposed to be unique to the entire document, so keep an eye out for that. document.getElementById() is the simp
by thaumaturgy 14y ago
Just a quick note of caution: id attributes are supposed to be unique to the entire document, so keep an eye out for that. document.getElementById() is the simplest way to target document elements that's supported by all browsers.
- jcr 14y agothanks thaumaturgy. I took my typical "make the problem simple" approach and replaced the function contents with: function displayx() { alert("Hello Nurse!"); } By the name change you can see my first guess was the name 'display()' might be causing the problem. As for Colin's question about for searching for this kind of stuff, it helps to make the problem smaller and more isolated ("bifurcation" is the more typical/pedantic way to say it). In this case you could search on the very first step, the [onclick], find a working example, and see if you can get the example to run properly. <button onclick="alert('Hello Nurse!');">Click Me</button> If it doesn't work, then you probably have a script blocker or popup blocker problem... or in my typical case, I've mistyped something important. ;) From there, find a simple example of calling a function from onclick, and see if you it to run properly. If it works, then compare your code to the example. If the simple example doesn't work, then you might have a bad example, or you mistyped something, or there might be something odd in your browser config, or you've just found a bug in your browser, or ... --keep trying to simplify and isolate the problem. The trouble with javascript searching and finding examples is finding bad examples. They're everywhere. The volume of bad JS code on the web is just staggering, but the worst parts are ancient, outdated and broken code still hanging around, and the existence of countless hacks to get around browser bugs/differences. The hacks can often look like horridly bad code, but sadly, they exist for a reason and they are seldom explained.