How do I load html into a variable with jquery

前端 未结 4 1092
予麋鹿
予麋鹿 2020-12-04 19:23

I know I can load in html in to a div with:

$(\"#my_div\").load(\"http://www.mypage.com\");

but I want to do is load html into a variable l

4条回答
  •  遥遥无期
    2020-12-04 19:44

    You could also create an element in memory and use load() on it:

    var $div = $('
    '); $div.load('index.php #somediv', function(){ // now $(this) contains #somediv });

    The advantage is that you can specify which part of index.php you want to load by using a selector ( #somediv )

提交回复
热议问题