Quantcast

document.getElementById not working after domConstruct.place

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

document.getElementById not working after domConstruct.place

dolot
This post has NOT been accepted by the mailing list yet.
OK.  So I have the following javascript:

function getDivHtml(element, url, args) {

    require(["dojo/request/xhr", "dojo/dom-construct"], dojo.hitch(this, function (xhr, domConstruct) {
        xhr(url, args).then(
            function (data) {
                domConstruct.place(data, element, "replace");
            },
            function (errPost) {

            }
        );

    }))

}

function loadUsersTab() {
   
    var theDiv = document.getElementById("usersDiv");

    var args = {
        method: "GET",
        preventCache: true
    };

    var url = "/admin/getUsers";

    getDivHtml(theDiv, url, args);
   
}

The first time I call loadUsersTab, the code executes properly and the usersDiv is loaded with the html from the server.  The second time I call the function, however, the var 'theDiv' is null.  I'm guessing that somehow the 'usersDiv' is being obliterated, but I'm not sure how or what needs to be done to correct this.

Let me know if you need to see anything else.

Thanks!
Dave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: document.getElementById not working after domConstruct.place

dolot
Found the solution.  I simply replaced the line:

domConstruct.place(data, element, "replace");

with:

element.innerHTML = data;

My guess is that .place was replacing 'element' with 'data', rather than inserting 'data' into 'element'.  I guess I misunderstood how place was working.  In this case, I don't really need domConstruct at all.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: document.getElementById not working after domConstruct.place

sg3235
You probably want “only” instead of “replace”

On Oct 19, 2016, at 11:35 AM, dolot <[hidden email]> wrote:

Found the solution.  I simply replaced the line:

domConstruct.place(data, element, "replace");

with:

element.innerHTML = data;

My guess is that .place was replacing 'element' with 'data', rather than
inserting 'data' into 'element'.  I guess I misunderstood how place was
working.  In this case, I don't really need domConstruct at all.






--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/document-getElementById-not-working-after-domConstruct-place-tp4007006p4007007.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Loading...