-2

I'm working on a personal home-page.html, so it resides on my computer and it is accesible only from my browser. Now for example I want get all element <a> from an external page and put them into a <div> when I click a button. Is it possible using a javascript funtion or jquery ? I have found answers about different domains, but it is not my case. I want to make something like this: https://jsoup.org/

and https://try.jsoup.org/~LGB7rk_atM2roavV0d-czMt3J_g . I tried with <frame> or load()but with bad results...

I'm trying this:

<button id="button">Click me</button>
<div id="txt"></div>

<script type="text/javascript">
    $("#button").click(function(){
        $.ajax({
            url:"http://cnt.rm.ingv.it",
            type:'GET',
            success: function(data){
                $('#txt').html($(data).find('a').html());
            }
        });
    });
</script>

<style type="text/css">
    #txt{
        width: 400px;
        height: 400px;
    }
    #button{}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
Origin
  • 39
  • 1
  • 6

1 Answers1

4

You can use ajax call for getting data and then get all tag. like this

$.ajax({
    url:url,
    type:'GET',
    success: function(data){
           $('div').html($(data).find('a').html());
        }
});

here url is url of page from where you want data

I have try your code and it is working for me I get out put like this

INGVL'IstitutoAmbienteVulcaniTerremotiComunicazioneStampa Lista TerremotiStrumenti Prodotti Scientifici ISIDeBollettino

To get all 'a' tag please try below code

$("#button").click(function(){
        $.ajax({
            url:"http://cnt.rm.ingv.it",
            type:'GET',
            success: function(data){
                $(data).find('a').map(function(){
                    $('#txt').append($(this).html());
                });        
            }
        });
    });

let me know if not working

thanks

Priya
  • 1,292
  • 9
  • 21
  • it's work. But why it return only one element ? and why I have in console many Failed to load resource: net::ERR_FILE_NOT_FOUND ? the error refers to jpg file... but I'm searching < a > or < table > – Origin Jan 17 '18 at 14:00