Reputation: 885
Two questions.
When i'm loading to div
file via jQuery .load()
$('.class').click(function(){
$(this).load("file.php");
});
file.php
is loading properly, but whenever i click on it (doesn't matter where, just in file.php
zone), page is blinking. Something like page refresh on click. Is there a way to prevent that?
Also the position of this page is always relative to div. Why doesn't position: absolute;
on body
in seperate css file for file.php
work for file.php
? I want to reset the position of file.php
to be on top of website (not z-index). Thanks.
Upvotes: 2
Views: 514
Reputation: 6668
Easy way.
$('.class').one("click", function(){
$(this).load("file.php");
});
Also is better to use .ajax()
for this to have more options and better control.
.load()
sometimes can first destroy content and then load new one. If you load bunch amount of data, that can made blink effect.
Upvotes: 1
Reputation: 26766
Your code
$('.class').click(function(){
$(this).load("file.php");
});
says any time you click in that div, (re)load the contents.
You may want to use jQuery's one method instead
$('.class').one("click", function(){
$(this).load("file.php");
});
which will only execute the first time you click inside the div.
As to position, we'd need to see code. Possibly one of your parent elements has position: relative
?
Upvotes: 2