#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    28
    Rep Power
    0

    Jquery function with Ajax


    Hello

    I was trying this:
    Code:
    <script> 
            $(document).ready(function(){
      $("p").click(function(){
        $(this).hide();
      });
    });
        </script>
        <p>hhhhhhhhhh</p>
    In a content I load with Ajax xmlhttprequest. The request only works in the home page, but not in the loaded content.

    Any idea how come?
    Thx. kr, C.
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,136
    Rep Power
    120
    I think it's because the <p> tag element(s), that may be in your responseText (from your AJAX request); was not loaded in the DOM (basically when the parent document onload event occurred and I would assume; that the jQuery function is in your parent document). So you are only able to access the DOM onclick event of the <p> tag element(s); that are in your parent document; where (I am assuming)... your jQuery function resides. Now I maybe wrong; but this is my hypothesis.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    28
    Rep Power
    0
    Originally Posted by web_loone08
    I think it's because the <p> tag element(s), that may be in your responseText (from your AJAX request); was not loaded in the DOM (basically when the parent document onload event occurred and I would assume; that the jQuery function is in your parent document). So you are only able to access the DOM onclick event of the <p> tag element(s); that are in your parent document; where (I am assuming)... your jQuery function resides. Now I maybe wrong; but this is my hypothesis.
    I solved it using the eval function.

IMN logo majestic logo threadwatch logo seochat tools logo