Im trying to load select content that is hidden on a page into a content div. To do to this i came across jquery's .load
and .empty
.
It seems to have gone wrong somewhere, but as far as i can see it should work,ideas where im going wrong on this ? And a wider question is .load / .empty the right functions to use for this or is there a simpler way ?
Ive attached my html and Js below, and also created a JSfiddle here : https://jsfiddle.net/poha5cb2/3/
Ive setup the following :
<a id="op-1">Open 1</a><br>
<a id="op-2">Open 2</a><br>
<a id="op-3">Open 3</a><br>
<hr>
<h2>CONTENT</h2>
<div id="content">
</div>
<hr>
<div class="hidden-content-to-be-loaded" style="display: none;">
<div id="one">
<h3>One</h3>
</div>
<div id="two" class="initial-close">
<h3>Two</h3>
</div>
<div id="three" class="initial-close">
<h3>Three</h3>
</div>
</div>
And for the JS ive written
$("#op-1").click(function(){
$("#content").empty();
$("#content").load("#one);
});
$("#op-2").click(function(){
$("#content").empty();
$("#content").load("#two);
});
$("#op-3").click(function(){
$("#content").empty();
$("#content").load("#three);
});