I am trying to load just the contents of a <div>
into another <div>
on the same page using a jquery function. But when the function triggers, it loads the entire <HTML>
document into the specified <div>
. Any idea why it would be doing this? My code is as follows:
Jquery:
function button1() {
$('#sidebar-content').fadeOut(function() {
$(this).load('#button1').fadeIn();
});
}
function button2() {
$('#sidebar-content').fadeOut(function() {
$(this).load('#button2').fadeIn();
});
}
HTML:
<div id="content-holder">
<div id="main-content" class="float-holder">
<div id="inner">
<h1>BRAND TRUTH</h1>
<div id="flashcontent">
<div id="button1">
<div id="content">
<h1>Brand Truth</h1>
<p>What this basically means is our way of working, the process involved by both ourselves and our client.</p>
<p>When the truth wheel process is followed, the end result is so much stronger.</p>
</div>
</div>
<div id="button2">开发者_如何学Python;
<div id="content">
<h1>Button 2 Content</h1>
<p>Some other content</p>
<p>Some other content x2</p>
</div>
</div>
</div>
<script type="text/javascript">
// <![CDATA[
var so = new SWFObject("working.swf", "working", "400", "400", "9", "#FFFFFF");
so.write("flashcontent");
// ]]>
</script>
</div>
<div id="sidebar">
<div id="sidebar-content">
Replace Content Here!
</div>
</div>
</div><!-- end #main-content -->
</div><!-- end #content-holder -->
.load()
is a function to load a remote webpage via AJAX, what you want is to use .html()
, like this:
function button1() {
$('#sidebar-content').fadeOut(function() {
$(this).html($('#button1').html()).fadeIn();
});
}
function button2() {
$('#sidebar-content').fadeOut(function() {
$(this).html($('#button2').html()).fadeIn();
});
}
.html()
without a parameter gets the html inside, so we're getting it from the button <div>
, then .html(string)
sets the html inside, which we're doing with the result.
精彩评论