Go Premium for a chance to win a PS4. Enter to Win

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 53
  • Last Modified:

Why does "getElementsByClassName" not work?

I've got a page that works, but I need more than one link to activate the Javascript function. Take a look:

This works: https://countryshowdown.com/map_stunt.php#

But, again, I need more than one link to open the same page. So, I tried this:

https://countryshowdown.com/map_fail.php and it doesn't fire.

How can activate the same function from two different links?

What do you think?
1 Solution
Robert SchuttSoftware EngineerCommented:
You can do this by looping over all objects in the array returned from getElementsByClassName.

Try something like this (note the first line on your site also contained the wrong function, missing the last bit):
var btn = document.getElementsByClassName("myBtn");
for(var b = 0; b < btn.length; b++) {
    btn[b].onclick = function() {
        modal.style.display = "block";

Open in new window


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now