Question: I found this JS code on-the-line:

```
var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "my_data.csv");

link.click();

```

and when I run it, it generates my\_data.csv and downloads it for me, I am looking to change this so when the user clicks a button, the code runs.I tried turning into a function called `Testing()` `function Testing()` and I have my link like this:

```
<a href="#" onClick="javascript:Testing()">Test</a>

```

but when i put that code in a function it does not work :( what am i doing wrong?

the error in my console says 'Testing is not defined'

Here is a jsfiddle: <http://jsfiddle.net/F6CWF/>

Answer: 
I pasted the code you've submitted into a local HTML file and it works fine for me (I did not add the test.js but pasted the code in script tags just before the closing body tag.
Here's the entire file (tested in Chrome only) 

```
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Test</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
    <link rel='stylesheet' href='test.css'/>
    <style type="text/css">            
        .draggable {
            width: 80px;
            height: 80px;
            float: left;
            margin: 0 10px 10px 0;
            font-size: .9em;
        }
        .ui-widget-header p, .ui-widget-content p {
            margin: 0;
        }
        #snaptarget {
            height: 140px;
        }
        body, html {
            background: url('http://i.imgur.com/FBs3b.png') repeat;
        }            
    </style>
</head>
<body>
    <div class="demo">
        <div id="draggable5" class="draggable ui-widget-content">
            <p>I snap to a 80 x 80 grid</p>
        </div>
    </div>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#draggable5").draggable({
                grid: [80, 80]
            });
        });
    </script>       
</body>

```
I think the problem might be that you're loading jquery and your js files in the head of your code. When it reads your js, it's looking for $(#draggable5), but draggable5 hasn't loaded yet, so it's an empty selector. Try moving your scripts to just before the close of your body element.