2

I have this code on my jquery

 participantText += '<div class="wrap_col td7"><input type="image" src="/pc/images/callgray.png" style="vertical-align: middle" class="actionInvite"></div>';

This is the action of class actionInvite

$(".actionInvite").click(function(){
    alert("Hello World");
});

but when i click the button it doesn't alert "Hello World".

It's just reload the page.

2 Answers2

4

You html is dynamically assigned.

For dynamic content

Try like this

$(document).on("click",".actionInvite",function(){
    alert("Hello World");
});
Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80
1

The image input type is actually a submit button (thus the reload). If you must use it, then you need to do this on your class or somewhere in your form submit event handler:

$(".actionInvite").closest('form').submit(function(e){
   e.preventDefault();
   alert("Hello World");
});

With html5 and modern CSS, I'd totally forgotten that input type actually exists. I'm sure a cleaner, better solution is out there on the horizon of your mind.

here's a jsfiddle for it.

kennasoft
  • 1,595
  • 1
  • 14
  • 26