Reputation: 317
I'm using jquery load() to display all documents on my website. My script in index.html file looks like this
<script type="text/javascript">
$(document).ready(function() {
$('#main-wrap').load("home.html");
$('#home').click(function() {
$('#main-wrap').load("home.html");
return false;
});
$('#wilgoc').click(function() {
$('#main-wrap').load("wilgoc.html");
return false;
});
etc...
In home.html
$(document).ready(function() {
//$(window).load(function() {
$('#slider').nivoSlider({effect:'fade', animSpeed:800, pauseTime:5000});
return false;
});
default for nivoslider is (window).load, but it doesn't work when I load home.html for the 2nd time... Any ideas? Thank you.
Upvotes: 1
Views: 2138
Reputation: 146191
The page has been loaded dynamically (#slider is a new DOM element) so it's not working
$('#home').click(function(e) {
e.preventDefault();
$('#main-wrap').load("home.html", function(){
$('#slider').nivoSlider({effect:'fade', animSpeed:800, pauseTime:5000});
});
});
EDIT:
Remove the document.ready from your home.html and keep that inside your index html file and call the plugin inside the callback function every time you load the home.html as folows (your index.html)
$(document).ready(function() {
$('#main-wrap').load("home.html", function(){
$('#slider').nivoSlider({effect:'fade', animSpeed:800, pauseTime:5000});
});
$('#home').click(function(e) {
e.preventDefault();
$('#main-wrap').load("home.html", function(){
$('#slider').nivoSlider({effect:'fade', animSpeed:800, pauseTime:5000});
});
});
...
...
});
Make sure you are not loading another full html file (with html. head e.t.c tags) inside your div.
Can you try this(replace each line):
setTimeout(function(){
$('#slider').nivoSlider({effect:'fade', animSpeed:800, pauseTime:5000});
}, 1000);
Upvotes: 1