geekInside
geekInside

Reputation: 588

add element to the DOM after load()

I cannot add element <p>TEST</p> before <h1> tags in my page

Here is my code (simplified) :

index.html

<div class="container" id="page_body"> BLABLA </div>

properties.html

<h1>Properties Management</h1>

menu.html

<li><a href="#" id="link_properties">Properties Repository</a></li>

JS

$("#page_menu").on('click', '#link_properties', function(e) {
    $("#page_body").load("properties.html"); // Properties
    $('h1').before('<p>TEST</p>');
});

Upvotes: 0

Views: 402

Answers (1)

Satpal
Satpal

Reputation: 133403

Use callback method. Assuming you want to insert <p> before <h1>Properties Management</h1> in properties.html

$("#page_menu").on('click', '#link_properties', function(e) {
    $("#page_body").load("properties.html", function(){
        $('h1').before('<p>TEST</p>');
    }); 
});

Upvotes: 2

Related Questions