Reputation: 109
I'm making a website with unchanged header and footer. The main div is changed when one clicks the sites. Here is the code:
<p id="item1">Item 1</p>
...
<script>
$("#item").click(function(){$("#main").load("item1.html");});
</script>
In item1.html:
<div id="sth"></div>
...
<script>
window.onload = function() {document.getElementById("sth").style.width = ...
</script>
Item1.html works fine when I open it separately (url = mywebsite.com/item1.html). But when I start it with the script above (index.html), the window.onload function don't work. How can I fix it?
Upvotes: 1
Views: 456
Reputation: 22711
You can use .load success callback function as mentioned below
$("#item").click(function(){
$("#main").load("item1.html", function(){
// your logics here
document.getElementById("sth").style.width =...
});
});
You can understand the use of window.onload
Upvotes: 2