The task is to implement the html page loading into a separate div on the page. It seems like for this you can use .load () .. Much has been written in the internet about this. For example, the code:

<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready(function(){ $('#but_load').click(function(){ $('#for_load').load('example.html'); }); }); </script> <style type='text/css'> #for_load{ width:500px; height:300px; border:2px solid black; margin-bottom: 10px; } #but_load{ width:500px; height:100px; border:2px solid black; } </style> <head> <body> <div id='for_load'></div> <div id='but_load'></div> </body> </html> 

That is, 2 divs are drawn, the first is the block for downloading the html file, the second is the button. Clicking on the first starts the function $ ('# for_load'). Load ('example.html'); Judging by what was written in the internet, the page in the # for_load div should be loaded right at the moment. But nothing happens.

Tell me what could be the error, or what I do not correctly.

  • 2
    The code is absolutely working. Check that in the console when clicking on the block - Barton
  • I started it in the Mozilla, everything works .. I should have looked at the console right away, it was done. In chrome swears on the path, said that there is no such file. The problem is solved, in principle. Thank. The next time I will be more attentive. - new_user_1

2 answers 2

It is necessary to begin to deflate porridge with the fact that for a start it is necessary to understand whether the assigned div is clicked with the mouse. To do this, simply replace the contents of the function with alert() , for example. Check it out. For some reason it seems to me that this div:

  <div id='for_load'></div> 

Does not have an adequate height, and, therefore, the click is not processed. Then, of course, check the наличие файла example.html for existence. If the file is in the root of the site, then it would be better to put a slash in front of it: /example.html.

  • Stupidly copied its code, created the file example.html and everything works. Tried to FF on Ubuntu - Barton
  • It seems to you. With alerts checked, of course, everything works. - new_user_1

Needless to say - in ff it will work, since the security mechanism is not implemented there, when the parameters that are not html in the house are being accessed, in other browsers this construction will not work based on chromium, and this is probably all the others))) ...

If you run other browsers with the option to disable security, you can achieve the display of elements not included in the house html.