user2520410
user2520410

Reputation: 479

Trigger a form action

I found this code, I suppose it triggers an event called "anAction" instead of a default form-action. But I cannot find any further information on that attribute. Is it valid HTML or does it belong to a library?

<form id="my_form" action="" data-trigger="anAction">

...</form>

Upvotes: 0

Views: 2063

Answers (2)

Roko C. Buljan
Roko C. Buljan

Reputation: 206028

It's a global attribute called data-*

more info here: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes and https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes

seeing this code looks like there's the use of preventing the form to take the browser default action returning a function that than uses that data-* value to call somehing, probably like:

$('[data-trigger]').submit(function( ev ){
   ev.preventDefault();

   var myData = $(this).data('trigger'); // anAction
   // now probably it uses that value to perform something...

});

might be the data-trigger in your case is used by a plugin that listens for that specific attribute...

Upvotes: 2

Mark Ormesher
Mark Ormesher

Reputation: 2408

Seems to be a part of this package: https://www.npmjs.org/package/trigger

Upvotes: 1

Related Questions