Diogo Leones
Diogo Leones

Reputation: 147

Html include with jQuery

Hy, I'm trying to found some jQuery code to allow me to insert several pages inside my website. I want to make two div's. In the first one I want to show the website (with all the website options like changing links and so on...) and in the other I the user to be able to insert notes about it and some other stuff...

This is what I'm doing:

<div id="div_top1" class="top">This is a paragraph.</div>

<div class="down"><button type="button" onclick="changediv()">Display Date</button></div>

<script>
function changediv()
{    
document.getElementById("div_top1").innerHTML=Date();
document.getElementById("div_top1").setAttribute("id", "div_top2");    
}
$("document").ready(function() {
     $('#div_top2').load('helloworld.php');
});

</script>

I know that the function is changin to div_top2, I just don't get it why it doesn't load the page

Upvotes: 0

Views: 87

Answers (2)

Nick
Nick

Reputation: 1102

As moonwave99 pointed out, try not to mix Javascript and JQuery too much. Something like this should do the trick:

<div id="div_top1" class="top">This is a paragraph.</div>

<button type="button" id="loadParagraph">Display Date</button>

<script>
    $("document").ready(function() {
       $('#loadParagraph').click(function() {
          $('#div_top1').load('helloworld.php');
       });
    });
</script>

Upvotes: 0

karthikr
karthikr

Reputation: 99620

You are not changing the id to div_top2 until the button has been clicked. And you have a listener in $(document).ready() on div_top2. Hence the page is not loading.

Try changing $('#div_top2').load('helloworld.php'); to $('#div_top1').load('helloworld.php');.

Upvotes: 2

Related Questions