views:

105

answers:

2

This code:

$("#permalink a").click(function(id){
var id = this.getAttribute('href');
$("#newPostContent").load(id, function() {
 $("#removeTrigger").click(function() {
 $("#removeThis").hideToggle();
 $("#postSingle").hideToggle();
 });
});
   $("#postSingle").fadeToggle();
   return false;
});

Shows #postSingle before the load function finish its work. How can I adjust it?

Thanks

(a lot of questions today, thank you, everybody :)).

A: 

Have you tried wrapping that in a document ready block? Like:

$(document).ready(function() {
  $("#permalink a").click(function(id){
  var id = this.getAttribute('href');
  $("#newPostContent").load(id, function() {
   $("#removeTrigger").click(function() {
   $("#removeThis").hideToggle();
   $("#postSingle").hideToggle();
   });
  });
   $("#postSingle").fadeToggle();
   return false;
});
});
Terry
See previous answer. I did. Nothing happens.
konzepz
He's talking about $.load(), not page load.
Tomas Lycken
+2  A: 

Put everything you want to happen after the load in the callback function:

$("#permalink a").click(function(id){
    var id = this.getAttribute('href');
    $("#newPostContent").load(id, function() {
        $("#removeTrigger").click(function() {
             $("#removeThis").hideToggle();
             $("#postSingle").hideToggle();
        });
        $("#postSingle").fadeToggle();
    });
    return false;
});
Tomas Lycken
SO SIMPLE. It works!
konzepz