Ask A Question

Notifications

You’re not receiving notifications from this thread.

I want to click on dynamically created HTML elements in stimulus js.

Abdul Basit Khan asked in Javascript

for example in jquery we do this =>

So instead of...
$(".myclass").click( function() {
// do something
});

We do this....
$('body').on('click', 'a.myclass', function() {
// do something
});


example for Javascript =>
document.body.addEventListener( 'click', function ( event ) {
if( event.target.id == 'btnSubmit' ) {
someFunc();
};

} );

my question is that how i achieve this is in stimulus js ?
because i'm working with ruby on rails when i render a form from back-end it's data-action and other things not working but out of the form everying is working fine.

Reply

i'm done

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.