jQuery csv file export fires multiple times I have a custom form, and I just want a button in the form that fires a jQuery plugin that generates a csv file for download. The problem I'm having is that it seems to fire multiple times for some reason, and I haven't been able to figure out why. I've tried both a button and a link, but I keep getting the same result.

Here's the form button:

$form['export_csv_button'] = array(
  '#type' =&gt; 'button',
  '#value' =&gt; t('Export to CSV'),
);


And here's my jQuery behavior:

(function ($) {
  Drupal.behaviors.ons_line_item_export = {
    attach: function (context) {
      $("#edit-export-csv-button").click(function() {
        $("#ons-line-item").tableExport({ type: "csv" });
        return false;
      })
    }
  };
})(jQuery);


Is there something obvious I'm missing that is making this happen?

Thanks.
Try this:

(function ($) {
  Drupal.behaviors.ons_line_item_export = {
    attach: function (context) {
      $("#edit-export-csv-button").once().click(function() {
        $("#ons-line-item").tableExport({ type: "csv" });
        return false;
      })
    }
  };
})(jQuery);


I added the jQuery.once() method.