All threads / I want to click on dynamically created HTML elements in stimulus js.
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.

Join the discussion

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

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

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

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.