How to put a whole html page in a div using jquery?

前端 未结 8 1465
暗喜
暗喜 2021-01-05 13:03

First of all I want everyone to know that I am absolute beginner so please be patient with me.

I want to know how am I going to put the entire html page in a div. I t

相关标签:
8条回答
  • 2021-01-05 13:38

    You use the .load() function:

    $("#footballPlayers").load('footballplayers.html body');
    

    Notice the selector after the URL. You can select elements from that page. I think you need the body, as having nested <html> tags could end badly.


    A few more comments about your code:

    You don't use this function more than once. Just shove all of your code into it:

    $(function() {
      // All of your code here.
    });
    

    I prefer this syntax, as it looks more functional and shows you what it does:

    $(document).ready(function() {
      // All of your code here.
    });
    

    Also, your code is really redundant. Try condensing it:

    $(document).ready(function() {
      $("#your_menu_container div").click(function() {
        $(this).load(this.id.substr(3).toLowerCase() + '.html').siblings().html('');
      });
    });
    
    0 讨论(0)
  • 2021-01-05 13:39

    TRY:

    $("#footballPlayers").load("footballplayers.html");
    
    0 讨论(0)
提交回复
热议问题