Is there a way to parse html content using javascript?
I have a requirement to display only a div from some other site into my site. Is that possible? For example consider I want to show only div#leftcolumn of w3schools.com in my site. Is this even possible?
How can I do the same using javascript or jQuery?
Thanks.
You need to have a look at Same Origin Policy:
For you to be able to get data, it has to be:
Same protocol and host
You need to implement JSONP to workaround it.
Though on same protocol and host, jQuery has
load()function which you would use like this:Another possible solution (untested) would be to use server-side language and you don’t need
jsonp. Here is an example with PHP.1) Create a php page named
ajax.phpand put following code in it:2) On some page, put this code:
Make sure that:
ajax.phpfileallow_url_fopenturned on from php.ini.yourDivwithidof element you want to put the received content in