Cicce19
Cicce19

Reputation: 153

load content to DIV tag on demand

I have a "comments" section on a webpage that I have hidden initially and when the user clicks the comments link the div tag (and comments) appear using the jQuery show/hide functions.

My question is: is it possible to load this content only when the comments link is clicked (not when the entire page is loaded)?

Upvotes: 2

Views: 3478

Answers (3)

Lee
Lee

Reputation: 13542

Yes. Use jQuery's load() function.

Upvotes: 0

Jacob Relkin
Jacob Relkin

Reputation: 163268

Given that comments_link and comments_container are the respective IDs:

$('#comments_link').click(function() {
     $('#comments_container').load('some-awesome-url-here');
});

This technique uses Ajax to make a request to a URL asynchronously and injects the resulting HTML into the specified element.

See jQuery.load

Upvotes: 5

ChrisLively
ChrisLively

Reputation: 88074

Yes... The technology you need to use is called Ajax. You can do it with jQuery or using the XMLHttpRequest object directly (not recommended).

What server technology are you using. e.g. php, .net, java,...

Upvotes: 0

Related Questions