1

I'm trying to use jQuery to simulate a click on an "Add Row" link. I want to trigger the javascript function attached to the link.

The function that adds the row is in a separate file, so I can't call it directly. (Specifically, it starts on line 57 of Django's admin inline.js file.) I guess my only other option is to trigger a click event on the link.

Table diagram

However, I tried to do this with:

$("tr.add-row a").trigger('click');

To no avail. It doesn't trigger the click event.

How can I get jQuery to click the link? (Or, ultimately, how can I add a row?)

Thanks in advance!

hao_maike
  • 2,929
  • 5
  • 26
  • 31

2 Answers2

1

I found the problem: Django's jQuery was namespaced in django.jQuery, not the standard jQuery or $.

I had to write

var jQuery = django.jQuery;
var $ = django.jQuery;

in front of my script, and now it works.

hao_maike
  • 2,929
  • 5
  • 26
  • 31
0

Trigger("click") should work, you can also try like this:

$("tr.add-row a").click();

http://api.jquery.com/click/

Most likely $("tr.add-row a") doesn't find anything.

Lance Hudson
  • 151
  • 7