user2470964
user2470964

Reputation: 1

Jquery load into DIV

I have the following problem:

I have in the first HTML:
(index.html)

<html>  
<head>
  <script type="text/javascript">  
     $(document).ready(function () {
       $("#options").load('options.html');
     });
  </script>  
</head>
<body>
  <div id="options"></div>
  <div id="containers"></div>
</body>
</html>

I load the second page (options.html) into div 'options'

and in the second HTML:
(options.html)

<html>
<head>
   <script type="text/javascript">
     $(document).ready(function () {
       $("#options").load('options.html');
     });
   </script>
<body>
<div id="options">
    <a href="anypage.html">any page</a>
</div>
</body>
</html>

is working! but I would like to load the link "any page" of page 'options.html' in the div 'containers' of page 'index.html'.

how do I do that?

Upvotes: 0

Views: 106

Answers (1)

Pranav
Pranav

Reputation: 8871

You just Need to do :-

 $("#containers").load('options.html #options');

from jquery docs:-

When calling .load() using a URL without a suffixed selector expression, the content is passed to .html() prior to scripts being removed. This executes the script blocks before they are discarded. If .load() is called with a selector expression appended to the URL, however, the scripts are stripped out prior to the DOM being updated, and thus are not executed.

Upvotes: 1

Related Questions