Is there a way to access elements of a loaded page [on hold]

264
March 15, 2017, at 11:33 PM

I'm using the jQuery function .load() to load a page.

Is there a way to access html elements contained in the loaded page from the source page once finished loading?

The only way I found is to add parameters in the URI. Is there an better way?

EDIT

Here is the code I'm trying to write:

$('.openInDialog').click(function(e) {
    var modal = $('#modal');
    var modalContent = $('#modal .modal-content');
    modal
        .on('show.bs.modal', function () {
            modalContent.load(e.currentTarget.href, function(){
                alert($(this).find('#firstName').html());
            });
        })
        .modal();
    e.preventDefault();
});

The line alert($(this).find('#firstName').html()); returns an empty string.

Answer 1

Suppose you load page contents into a div with an id page:

$("#page").load("page.html");

In that case, you need to add a callback function and access the added elements with the help of children():

$("#page").load("page.html", function() {
    $(this).children(); // Selects everything that was loaded
    $(this).children("span"); // Selects all loaded span elements
    $(this).children(".test"); // Selects all loaded elements with test class
});
READ ALSO
Use single ajax function for all events with custom data params

Use single ajax function for all events with custom data params

I don't know if the question itself is correct, but here is explanation

272
Why is that when I refresh my current link, my current link goes back to my home page link #? I'm using Angular JS plus outside JS

Why is that when I refresh my current link, my current link goes back to my home page link #? I'm using Angular JS plus outside JS

[Why is that when I refresh my link, my current link goes back to my home page link? Meaning, that when I am on my current page and have the active link highlighted, and when I refresh, it returns to my home page link but still stays on the same page link]

320
Change color of dropdown background color

Change color of dropdown background color

The background color for my property address picker dropdown is currently transparent and I'd like to make it white, can't seem to figure it out no matter how much I mess with it:

389
How to display JSON data in bootstrap table

How to display JSON data in bootstrap table

I am trying to use bootstrap table to load json datahow can i load an external json file into the bootstrap table below

922