Clicking anchor should execute javascript not go to new page

前端 未结 5 682
忘掉有多难
忘掉有多难 2021-01-14 07:45

I have a HTML anchor that when clicked should make a div slide up or down (I call JQuery\'s .slideToggle(); function);

My Problem: When

5条回答
  •  有刺的猬
    2021-01-14 08:17

    instead of write inline JavaScript code, try below. preventDefault method prevents the default action of the element. In your case, it prevents default action of the click event, which is, going to new page

    $(".interactiveLink").on("click", function(e){
       e.preventDefault();
       $('#attachFileContainer').slideToggle();
    });
    

    Make your html code as

    Attach File
    

提交回复
热议问题