How for $ (document) works

I am new to this, so I regret asking myself confused and simple thoughts :-)

My JS Code does not work for moadal with form loading from ajax call and php side.

I think I need to call a function in a way like this

$(document).on('click', '#tags', function () 

I'm not right now, how should I change the source code to this - maybe someone can help me and explain it to me?

 $('#tags').on({ click: function(e) { e.preventDefault(); alert('geklickt');}, mouseenter: function(e) { alert('mouse enter!'); } }); 

If I use only "$ (" # tags ")," it will not work for me ...

Hope I can explain what I want to do.

Also, I finally transcoded this code

 $(document).ready(function() { bookIndex = 0; $('#bookForm') // Remove button click handler .on('click', '.removeButton', function() { var $row = $(this).parents('.form-group'), index = $row.attr('data-book-index'); // Remove fields $('#bookForm') .formValidation('removeField', $row.find('[name="book[' + index + '].title"]')) .formValidation('removeField', $row.find('[name="book[' + index + '].isbn"]')) .formValidation('removeField', $row.find('[name="book[' + index + '].price"]')); // Remove element containing the fields $row.remove(); }); }); 

What parts should I change that the support of "document.on" is avivable?

+5
source share
1 answer

Just pass in the string selector :

 $(document).on({ click: function(e) { e.preventDefault(); alert('geklickt'); }, mouseenter: function(e) { alert('mouse enter!'); } }, '#tags'); 
+2
source

Source: https://habr.com/ru/post/1257510/


All Articles