How to prevent page refresh when tag clicked?

前端 未结 4 555
眼角桃花
眼角桃花 2021-01-25 15:28

I need to pass a parameter into the URL and at the same time prevent page from reloading when I click any tag with a blank href attribute (

4条回答
  •  旧时难觅i
    2021-01-25 16:17

    You can use Attribute equal selector to prevent click event in case of blank href like,

    $('.list-group-item a[href=""]').click(function (event) { // where href are blank
       event.preventDefault();
    });
    

    And I would like to suggest don't make empty the href's, you can place # if no links are there.

提交回复
热议问题