-1

I am tying to understand a project where used JQUERY to manipulate the DOM. I have the following element:

<a data-modal-trigger data-modal-target=".modal-confirm" class='confirm-modal-trigger' style='width: 1px;'></a>

In the javascript code I have this tag clicked by the code:

$(".confirm-modal-trigger").click();

But there is no call-back function definiton attached to this event like:

$(".confirm-modal-trigger").click(function(){....});

or $(".confirm-modal-trigger").on("click", function(){....});

I am searching trough the whole project files and nothing. Then what is the purpose of clicking this a tag if there is no href attribute nor there is a call back function defined when button is clicked?

And the most strange part is that when I comment this line

$(".confirm-modal-trigger").click();

The code doenst work as it should.

* EDIT *

I read the proposed original answer, and I still don't uderstand why when commented the .click() the pop-up window that normally appears (when not commented) doesen't appear when I comment this line. If there is no action behind it - just a sematnic meaning, why I observe that behaviour?

Kunj
  • 1,980
  • 2
  • 22
  • 34
Hairi
  • 3,318
  • 2
  • 29
  • 68

1 Answers1

0

This is a guess (without seeing the codebase) but: most probably the event is delegated to a parent or ancestor element, which could make it quite hard to find in the code.

Say the element .confirm-modal-trigger has a parent, a div with ID "foo". The event may well be bound like so:

$('#foo').on('click', '*', function() {});

or

$('#foo').on('click', '> *', function() {});

or

$('#foo').on('click', 'a', function() {});

...the list of possibilities is potentially endless.

Mitya
  • 33,629
  • 9
  • 60
  • 107