简体   繁体   中英

.load() whole page to modal and .remove() specific div from it at the same time with JQuery

I need to exclude some divs (one or several) from the page that I .load() from the same domain to modal, I use this to load pages:

$(document).ready( function() {
$("#div-id-where-to-load-page").load("loaded-page-url");});

I tried something like this:

$(document).ready( function() {
$("#div-id-where-to-load-page").load("loaded-page-url").remove(#div-id-to-remove);});

and its not working, if I break it to separate functions it doesn't work either, I am new to JS, what am I doing wrong?

All scripts are loaded from the separate file (if it is important).

You can have a callback function on the .load() method. This way you guarantee that the elements you want to remove are already loaded to the DOM when you call the .remove() .

$(document).ready( function() {
    $("#div-id-where-to-load-page")
        .load("loaded-page-url", function() {
            $('#div-id-to-remove').remove();
        });
});

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