Unexpected page refresh in Chrome

I have been confronted with this strange behavior for some time now and cannot find a workaround.

There is a button with specific methods caused by a click. Firefox works well. In Chrome, it just refreshes the whole page.

$("#modoComparativa").click(function(){
   if($(this).hasClass("active")){
                $('#histFromDate').attr("placeholder","Date 1");
                $('#histToDate').attr("disabled","disabled").attr("placeholder","Date 2");
                startDatepickerComp();
            }
            else{
                $('#histFromDate').attr("placeholder","Initial date");
                $('#histToDate').attr("disabled","disabled").attr("placeholder","Final date");
                startDatepicker();
            }
            $('#clearDates').attr("disabled","disabled");
            // This function calls another function causing the odd behavior in Chrome
            requestGraph(idDetail, idArea, "", "");
        });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Run code

If I comment on everything except the selector and the click method call, the behavior will be the same. It refreshes everything.

I cannot figure out how to debug this, since every time I click the button, the whole page is refreshed and there are no errors / errors left in the browser debugger.

Any ideas would be appreciated.

Edit - add a selector as requested:

<div class="form-group"><button class="tooltip3 btn btn-default glyphicon glyphicon-random" id="modoComparativa" data-toggle="tooltip" title="ACTIVAR COMPARATIVAS" data-placement="bottom"></button>
                            </div>
+4
source share
1 answer

false , - html (, ).

$("#modoComparativa").click(function(event){
    event.preventDefault();

    // your existing code
}

: html...

, type = "button", .

<button type="button" class="tooltip3 btn btn-default glyphicon glyphicon-random" id="modoComparativa" data-toggle="tooltip" title="ACTIVAR COMPARATIVAS" data-placement="bottom"></button>

lonesomeday http://api.jquery.com/event.preventDefault/

+6

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


All Articles