lee lee - 7 months ago 66
Javascript Question

Get content from a specific div that is in another page

ajax and jquery newbie here.

Let's say I want the current page to only get div 3 content that's from another page and load it inside div 1, how do I do that with jquery or ajax? Both page are on the same domain name.

example.com/current-page

<div id="1"> </div>
<div id="2"> </div>


example.com/another-page

<div id="3"> </div>
<div id="4"> </div>

Answer

You need to make use of jQuery "load" method to load it (like this):

 $('#result').load('exampledomain.com #targetdiv');

Please note there is a space between domain name and #target