简体   繁体   中英

Jquery - $.GET Place In Closest Div

So this is probably very easy but for some reason I can't get it to work. I have a $.get function that runs properly. I want the data/results to load into the closest div. When I identify the div specifically, everything works fine:

$.get( lk, function(data) {
        $("div.tcontainer").html(data);
    });

But when I try to look for the closest div, it does not work. I have a few divs on the page (dynamically) and they have the same attributes so i need to find the closest div and load the data into that div like:

$.get( lk, function(data) {
        $(this).closest("div.tcontainer").html(data);
    });

But this does not work. Can someone help me find the closest div using the code above. Thank you.

The value of your this variable is not a DOM object in that context. You will need to set another closure variable and then access that closure variable inside the callback. If your closure value that you want is this , then do var that = this; and replace $(this) with $(that)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM