Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load content of a div on another page

Tags:

You will see from this code that it loads the content URL from the hash tag. Is there anyway to load only a single div element from that external page.

$(function() {     if(location.hash) $("#content_inload").load(location.hash.substring(1));      $("#nav a").click(function() {             $("#content_inload").load(this.hash.substring(1));     }); }); 

so something like after .substring(#inload_content(1))

but that does not work.

Thanks

like image 966
RIK Avatar asked Nov 04 '10 21:11

RIK


People also ask

How to load another page in div?

To load external HTML into a <div>, wrap your code inside the load() function. To load a page in div in jQuery, use the load() method.

How to load specific div using jQuery?

jQuery - AJAX load() Method The load() method loads data from a server and puts the returned data into the selected element. Syntax: $(selector). load(URL,data,callback);

How to load page in jQuery?

The Load() method in jQuery helps to load data from server and returned into selected element without loading the whole page. Syntax: $(selector). load(URL, data, callback);


2 Answers

You just need to add a jquery selector after the url.

See: http://api.jquery.com/load/

Example straight from the API:

$('#result').load('ajax/test.html #container'); 

So what that does is it loads the #container element from the specified url.

like image 190
Radu Avatar answered Oct 16 '22 16:10

Radu


Yes, see "Loading Page Fragments" on http://api.jquery.com/load/.

In short, you add the selector after the URL. For example:

$('#result').load('ajax/test.html #container'); 
like image 24
Zack Bloom Avatar answered Oct 16 '22 17:10

Zack Bloom