SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DOM loaded through xmlhttprequest not detected by jquery in GM

    Hi,

    I'm loading content using an XMLHttpRequest and sending it to a
    Code:
    div
    on the fly in Greasemonkey. However, when I try to traverse through this newly loaded content and retrieve the innerHTML, jquery returns a null.

    My code is as such
    Code:
    var xhReq = new XMLHttpRequest();
     xhReq.open("GET", linksRaw, false);
     xhReq.send(null);
     var serverResponse = xhReq.responseText;
     var tempDiv = document.createElement('div');
    tempDiv.setAttribute("id", "myContainer");
    
    tempDiv.innerHTML = serverResponse.replace(/<script(.|\s)*?\/script>/g, '');
    var letsTry = $("div#myContainer .orgList").html();
    alert (letsTry);
    The alert returns a "null" when I know that .orgList link has anchor text.

    Also, getElementsByClassName isn't working either.
    I'm using the latest update of Greasemonkey and FF 3.6

    Thanks

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    jquery is looking in window.document for your div(the default). It doesn't exist in any document. You created it but haven't added it to anything.

    Try $(".orgList", tempDiv).html()


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •