Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

input type image click event in jquery

I am trying to navigate to another page using jquery

Markup :

<input type="image" name="ImageButton1" id="btnCancel" src="../images/btn_cancel.gif" />

JS

 $('input[type="image"][id^="btnCancel"]').live('click', function () {
        window.location.replace('default.aspx');
 });

Page just refreshes, it does not navigate to desired page. when i change type=button it works.

How to achieve the same by keeping type as image only ?

like image 826
Shaggy Avatar asked Sep 01 '25 16:09

Shaggy


2 Answers

$("#btnCancel").on('click', function () {
        window.location.href = 'default.aspx';
});
like image 58
Nikhil Talreja Avatar answered Sep 04 '25 06:09

Nikhil Talreja


Use preventdefault:

$('input#btnCancel').on('click', function (e) {
        e.preventDefault();
        window.location.replace('default.aspx');
 });
like image 31
Arvind Bhardwaj Avatar answered Sep 04 '25 06:09

Arvind Bhardwaj