Reputation:
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.
Upvotes: 2
Views: 42
Reputation: 1593
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.
Upvotes: 1
Reputation: 25352
You html is dynamically assigned.
For dynamic content
Try like this
$(document).on("click",".actionInvite",function(){
alert("Hello World");
});
Upvotes: 4