return or send variable to onchange event
<p>I am trying to achieve the same functionality of a function from two separate events. So the function I created is:</p>

<pre><code>function adding_stuff() {
    var names = [];
    var dates = [];
    for(var i = 0; i &lt; this.files.length; i++) {
        //adding stuff to names and dates
    }
    $(".primary .panel-content").append("&lt;ul class='list-unstyled'&gt;&lt;/ul&gt;");
    for(var i in names) {
        var li = "&lt;li&gt;";
        $(".primary .panel-content ul").append(li.concat(names[i]))
    }
}
</code></pre>

<p>There are two buttons <code>primary</code> and <code>secondary</code>. I want the same functionality for both the functions but the output in different <code>&lt;div&gt;</code>. Currently the selected <code>&lt;div&gt;</code> is <code>".primary"</code>, however I want this to depend on the button which has been clicked.</p>

<p>The function is triggered using: </p>

<pre><code>$("#primary").onchange = adding_stuff;
$("#secondary").onchange = adding_stuff;
</code></pre>

<p><strong>NOTE:</strong> <code>primary</code> and <code>secondary</code> are inputs of type <code>file</code>.</p>
