1
Besides simply loading dynamic website content into a [div] tag with jQuery's .load(), you can also load just a specific section of a page, define the webpage path with variables, and even pass URL paramaters in the address.
If you only want to load a specific part of the page, you can add an element selector after the webpage path.
These will all load only a specific part of the page.
- $('#myDynamicDiv').load('mypages/pagetoload.html #contentDiv');
- $('#myDynamicDiv').load('mypages/pagetoload.html #mainCol .primaryDoc');
- $('#myDynamicDiv').load('mypages/pagetoload.html .article:first');
You can also use a string variable that contains the path to the webpage or only part of the path, like the filename.
These will all load the same page, but use different variables
- $('#myDynamicDiv').load('mypages/'+myPage+'.html');
- $('#myDynamicDiv').load(myDirectory+'myPage.html');
- $('#myDynamicDiv').load(pathToMyPage+tplExtension);
The end of the URL can have parameters also. Consider combining several URL parameters into a single string, like example 3.
These will all load the same page, but pass different parameters
- $('#myDynamicDiv').load('mypages/pagetoload.html?item=519);
- $('#myDynamicDiv').load('mypages/pagetoload.html?news='+newsId+'&ver=1);
- $('#myDynamicDiv').load('mypages/pagetoload.html?'+urlParamString);
Finally, you can combine all these extra options together (you may produce cleaner code if you use the .get() method).
This will load only a specific part of the page using variables, and pass URL parameters to the page
- $('#myDynamicDiv').load('mypages/'+myPage+'.html?news='+newsId+'&'+urlParamString+' #mainCol .primaryDoc');
Let's get into contact so you learn more about us and we can create solutions for you!