user2609980
user2609980

Reputation: 10484

How to add content of div with certain class to other page?

I want to display one part of a web page on another page. This specific div has a class name, but not an id. The parent div does have an id, and more than one child div.

I tried using an iframe, but I can only manage to get the whole page displayed. When I tried to use jQuery's .load() method nothing showed. How can I use an iframe to only display one div?

And if I cannot use an iframe to do so, is there another way to do it?

Upvotes: 0

Views: 62

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

You can use the load() method...

Try

<div id="mycontainer"></div>

then

jQuery(function($){
    $('#mycontainer').load('/mypageurl.xxx .myclass')
})

It will load the contents of element with class myclass in the page with url mypageurl.xxx to an element with id mycontainer in the current page

Upvotes: 1

Related Questions