Home > Back-end >  Get var value as html from other file and append it using jQuery
Get var value as html from other file and append it using jQuery

Time:10-21

I have one file named my_list.php. In my_list.php

<div >
 My Inner Content
</div>

I have another file called utility.js. In utility.js

var my_content = '<div >
                     <div ></div>
                      Some content
                  </div>';
$(my_content).appendTo("body");

Now I want to load my_list.php inside inner-cover for that I wrote the following code

var my_content = '<div >
                     <div ></div>
                      Some content
                  </div>'
$('.inner-cover').load('my_list.php');
$(my_content).appendTo("body");

But this code is not working. How can I include my_list.php inside inner-cover Please help.

CodePudding user response:

Seems you just need to swap the code order

change

$('.inner-cover').load('my_list.php');
$(my_content).appendTo("body");

to

$(my_content).appendTo("body");
$('.inner-cover').load('my_list.php');

Because if we want to invoke load(),first we need to make sure the element exists

  • Related