Lewis Day Lewis Day - 4 months ago 12
Javascript Question

How can I have this have a default page loaded into the div on pageload?

I need this to have a default page on load of

aboutme.php
but still have all the same functionality

function

$(function(){
$(document).on('click', '.content-link, #profile-body a',function(e){
e.preventDefault();// prevent browser from opening url
$('#profile-body').load(this.href);
});
});


body

<div id="profile-body"></div>


So before any link is clicked to load into the div; the div has already loaded the
aboutme.php
page, hopefully this makes sense, and thankyou for any help in achieving this.

Answer

You have this for the links:

$(function(){
    $(document).on('click', '.content-link, #profile-body a',function(e){
         e.preventDefault();// prevent browser from opening url
         $('#profile-body').load(this.href);   
    });
});

But you need: when the page loads,

$(document).ready(function() {
    var defaultPage = "aboutme.php";
    $('#profile-body').load(defaultPage);
});

And that's all. Just add this code after your code, don't replace your version.

Comments