Using a href onclick to update div without reloading page?

前端 未结 4 688
长情又很酷
长情又很酷 2021-01-20 04:40

I used this existing question to help me out: HTML - Change\\Update page contents without refreshing\\reloading the page

The template-comparison.php file fetches the

4条回答
  •  暖寄归人
    2021-01-20 05:12

    If you are using jQuery you can avoid DOM onClick triggers and use the jQuery events instead. Also when you have a hashtag as href in your anchors it puts the hashtag in the URL when clicked because it assumes it is an element ID. You can change that as show below, or even ommit it:

    link text
    

    Now you can bind the events using jQuery:

    $(document).ready(function(){
        $('.foo').on('click', function(e){
            e.preventDefault();
            prescand($(this).data("target"));
        });
    });
    

    You might also use the $('a') jQuery selector, but usually you want to be a bit more specific and target only certain anchors by grouping them together with a certain class.

    The loading function is OK as is.

提交回复
热议问题