Let's use a function to make this easier. I'll call it load_divs
:
HTML:
<a style="cursor: pointer;" onclick='load_divs();return false;'>Display content</a>
JavaScript:
function load_divs() {
$("#col2").load("oldPage.htm #div1");
$("#col2").append($("<div>").load("oldPage.htm #div2"));
}
An even better way to attach this event handler would be to give your a
element an id
and add the handler using jQuery:
HTML:
<a id="display_link" style="cursor: pointer;">Display content</a>
JS:
$("#display_link").click(function() {
$("#col2").load("oldPage.htm #div1");
$("#col2").append($("<div>").load("oldPage.htm #div2"));
});
Alternatively, if the divs you want to load are side-by-side in the DOM, you can wrap them in another div then load just that one.