4usolutions 4usolutions - 2 months ago 12
jQuery Question

How .on works for $(document)

I'm a newbie for that, so i'm sorry for asking confused and simple thinks :-)

My JS Code wont work for a moadal with a form that is loading from a ajax-call and php side.

I think i have to call the function in way like this

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


I dont now how i should change the original code into this - maybe someone can help me and explain it for me?

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


If i only use the "$('#tags')" it wont work for me...

Hope i could explain what i want to do.

Answer

Just pass string selector:

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