M
M
mars13112019-05-09 21:38:23
JavaScript
mars1311, 2019-05-09 21:38:23

How to access elements generated by javascript?

I need to create a function that is called when a block is clicked, but since this block is generated via javascript the following way is:

$('#delete').click(function(){
   alert('works');
})

doesn't work(
How can I access elements through the DOM?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaliy Pershin, 2019-05-09
@mars1311

You can delegate an event:

$('body').on( 'click', '#delete', function( event ) {
 alert('works');
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question