3

I have this button on my page, which points to the function download():

<a class="myButton" onclick='return download(this);'>Download</a>

download():

function download(button)
{
  console.info(button);
  return true;
}

After clicking the button I get:

Uncaught TypeError: download is not a function
    at HTMLAnchorElement.onclick (mbnet.html:1153)

However, If I open the developer console and execute download then I get:

function download(button)
{
  console.info(button);
  return true;
}

If I execute download() then I get:

undefined
true

So obviously the function is defined, why am I seeing this error? Is it because I render the button with fluid?

I also tried to wrap the function download() with $(document).ready();, but this changed nothing.

$(document).ready(
  function() {

    function download(button)
    {
      console.info(button);
      return true;
    }
  }
);
Black
  • 18,150
  • 39
  • 158
  • 271

1 Answers1

5

Please change the function name.

<html>
<script>
function download1(button)
{
  console.info(button);
  return true;
}
</script>
<body>
    <a class="myButton" onclick='download1(this);'>Download</a>
</body>
</html>
Sanjay
  • 2,481
  • 1
  • 13
  • 28
  • I changed it to download1 and it works! If I execute download in the console now, then I get `VM5344:1 Uncaught ReferenceError: download is not defined at :1:1` So it seems like `download` is not even reserved ?! Is this a strange browser bug? – Black Jan 25 '17 at 10:50
  • \*laugh\*...... –  Jan 25 '17 at 10:53