Reputation: 3601
I have an html file, and I am using .load()
to load some part of div photo_index
from another html file into a div (profile_wrapper_container_FormLogs
) in my original html. It does load the html file. But it loads the whole html file, and not only the div. What do I do to load only the needed div, ie.photo_index
, from another html? Any help will be much appreciated. Thank you!
html:
<div id="profile_leftbar">
<div id="profile_wrapper_container_summary">
<div id="profile_container_summary">
<div id="profile_summary">
<div id="profile_box1" class="box">
<a href="kkh.html" id="photo"><p>Photo</p>
<p>450</p></a>
</div>
<div id="profile_box2" class="box">
<a href="#" id="video"><p>Video</p>
<p>132</p></a>
</div>
<div id="profile_box3" class="box">
<a href="#" id="page"><p>Page</p>
<p>14</p></a>
</div>
<div id="profile_box4" class="box">
<a href="#" id="forum"><p>Forum</p>
<p>51</p></a>
</div>
<div id="profile_box5" class="box">
<a href="#" id="followers"><p>Followers</p>
<p>551</p></a>
</div>
<div id="profile_box6" class="box">
<a href="#" id="following"><p>Following</p>
<p>317</p></a>
</div>
<span class="clear_left"></span>
</div>
<div id="profile_status">
<p>What???</p>
</div>
</div>
</div>
<div id="profile_wrapper_container_FormLogs">
<div id="profile_container_status_form">
<textarea class="profile_status_form"></textarea>
</div>
<div id="profile_container_logs">
<div class="profile_logs">
<p>Added photo on 30th oct</p>
</div>
<div class="profile_logs">
<p>Created a blog <a href="#">'This world'</a> on 17th oct.</p>
</div>
<div class="profile_logs">
<p>Added photo on 16th oct</p>
</div>
<div class="profile_logs">
<p>Updated status 'Do you really think so?' on 10th Oct.</p>
</div>
<div class="profile_logs">
<p>Uploaded video.</p>
</div>
<div class="profile_logs">
<p>Added photo on 30th oct</p>
</div>
<div class="profile_logs">
<p>Created a blog <a href="#">'This world'</a> on 17th oct.</p>
</div>
<div class="profile_logs">
<p>Added photo on 16th oct</p>
</div>
<div class="profile_logs">
<p>Updated status 'Do you really think so?' on 10th Oct.</p>
</div>
<div class="profile_logs">
<p>Uploaded video.</p>
</div>
<div class="profile_logs">
<p>Added photo on 30th oct</p>
</div>
<div class="profile_logs">
<p>Created a blog <a href="#">'This world'</a> on 17th oct.</p>
</div>
<div class="profile_logs">
<p>Added photo on 16th oct</p>
</div>
<div class="profile_logs">
<p>Updated status 'Do you really think so?' on 10th Oct.</p>
</div>
<div class="profile_logs">
<p>Uploaded video.</p>
</div>
</div>
</div>
</div>
another html:
<div id="test">
<h1>Testing the .load()</h1>
</div>
<div id="photo_index">
<div id="tools_photo">
<ul id="tools">
<li><a href="#">All</a></li>
<li><a href="#">Album</a></li>
<li><a href="#">Tagged Photo</a></li>
<li><a href="#">Upload Photo</a></li>
<span class="clear_left"></span>
</ul>
</div>
<div id="photo_index_page">
<div id="container_thumbnail_container">
<div class="thumbnail_container">
<a href="#" class="gallery" title="{{photo.title}}"><img src="img2.jpg" class="thumbnail" /></a>
</div>
<div class="thumbnail_container">
<a href="#" class="gallery" title="{{photo.title}}"><img src="img3.jpg" class="thumbnail" /></a>
</div>
<div class="thumbnail_container">
<a href="#" class="gallery" title="{{photo.title}}"><img src="img4.jpg" class="thumbnail" /></a>
</div>
<div class="thumbnail_container">
<a href="#" class="gallery" title="{{photo.title}}"><img src="img5.jpg" class="thumbnail" /></a>
</div>
<div class="thumbnail_container">
<a href="#" class="gallery" title="{{photo.title}}"><img src="img.jpg" class="thumbnail" /></a>
</div>
<div class="thumbnail_container">
<a href="#" class="gallery" title="{{photo.title}}"><img src="img2.jpg" class="thumbnail" /></a>
</div>
<div class="thumbnail_container">
<a href="#" class="gallery" title="{{photo.title}}"><img src="img3.jpg" class="thumbnail" /></a>
</div>
<div class="thumbnail_container">
<a href="#" class="gallery" title="{{photo.title}}"><img src="img4.jpg" class="thumbnail" /></a>
</div>
<div class="thumbnail_container">
<a href="#" class="gallery" title="{{photo.title}}"><img src="img5.jpg" class="thumbnail" /></a>
</div>
<span class="clear_left"></span>
</div>
</div>
</div>
.js:
$(document).ready(function () {
$(".box a").click(function () {
$("#profile_wrapper_container_FormLogs").load(this.href + "#photo_index");
return false;
});
});
Upvotes: 2
Views: 2567
Reputation: 309
suppose your target division element in another html file have id #target (file name is another.html) suppose your current division element in current html page have id #result
if you want to load that target element to your current result element then
use this code $("#result").load("another.html #target", null, function(){ );
the first argument is the file url, second argument is the data to send to that url, third is the call back function. the #target specifies the target element in the another.html page.
thank u
Upvotes: 0
Reputation: 20418
Try this
var toLoad = this.href+' #photo_index';
$('#profile_wrapper_container_FormLogs').load(toLoad)
Upvotes: 0
Reputation: 74738
Your current code will make a url like http://dummy.com/index.html#photo_index
and this will load the whole html from the page.
$("#profile_wrapper_container_FormLogs").load(this.href + "#photo_index");
Put a " "
space before " #photo_index"
:
$("#profile_wrapper_container_FormLogs").load(this.href + " #photo_index");
//-------------^^--put a space here
or this way:
$("#profile_wrapper_container_FormLogs").load(this.href + " " +"#photo_index");
//--------------^^--put a space here
Upvotes: 3