-1

I need to append from a class id to it how do i do this?

https://www.geonet.org.nz/earthquake/ is the source and the id from the class is publicid how would i do this please if you understand my question i need somethins like this

<a href="www.geonet.org.nz/earthquake/ + "publicid"

i have tried the above but no luck i did think it would not work though.

Thank you if anyone can help me it is probably a simple answer too

Tim
  • 3
  • 3
  • Welcome to SO. Please elaborate a bit more with your question as otherwise those who want to answer have to guess many things which won't bring you useful answers. From comments you left under a first answer it appeared to me you're concerned about parsing and processing XML with PHP and suggest you relate to the existing reference question. You can always [edit] your question and make it more clear what you're stuck with. Also compare [help]. – hakre Dec 17 '22 at 10:42

1 Answers1

-1

You have to make changes in index.php and main.js.

In index.php you insert the new classes "recrent" and "strongest" for the hyperlink tags:

...
<div class="row">
    <div class="span12 time_since invisible">
    <center><span class="hours"></span> hours <span class="minutes"></span> minutes <span class="seconds"></span> seconds since last earth quake
    </div></center>
    <div class="span6 recent_quake invisible">
        <h3>Live - Latest Quake<br>
        Magnitude: <span class="magnitude"></span> <br>Depth: <span class="depth"></span> <br> Time: <span class="origintime"></span> NZDT 24hr <br>PublicID: <a class="recent" href="" target="_blank"><span class="publicid"></span></a>
        </h3>
    </div>
    <div class="span6 strongest_quake">
        <h3>Strongest Quake Last 24 Hours<br>
        Magnitude: <span class="magnitude"></span> <br>Depth: <span class="depth"></span> <br> Time: <span class="origintime"></span> NZDT 24hr <br>PublicID: <a class="strongest" href="" target="_blank"><span class="publicid"></span></a>
        </h3>
    </div>
</div>
....

In the file main.js you have to add one line in the function "checkResponse()" and one line in the function "populateStrongest(thisQuake)". The added lines are marked with "// new line":

function checkResponse() {
    $.ajax({
        url: url,
        crossDomain: true,
        dataType: 'json'
    }).done(function(data){
        thisQuake = data.features[0];
        if ( recentQuake != thisQuake.id ) {
            recentQuake = thisQuake.id;
            time = getTime(thisQuake.properties.origintime);
            console.log('TotalSeconds', totalSeconds);

            $('.xcoord', '.recent_quake').html(thisQuake.geometry.coordinates[0]);
            $('.ycoord', '.recent_quake').html(thisQuake.geometry.coordinates[1]);
            $('.depth', '.recent_quake').html(thisQuake.properties.depth.toFixed(0) + ' km');
            $('.publicid', '.recent_quake').html(thisQuake.properties.publicid);
            $('.origintime', '.recent_quake').html(time);
            $('.magnitude', '.recent_quake').html(thisQuake.properties.magnitude.toFixed(1));
           // new line
            $('.recent', '.recent_quake').attr("href","https://www.geonet.org.nz/earthquake/"+thisQuake.properties.publicid);

            $('.recent_quake').removeClass('invisible');
            $('.latest').removeClass('latest');
            qMap.drawOverlay({
                lat: thisQuake.geometry.coordinates[1],
                lng: thisQuake.geometry.coordinates[0],
                content: '<div data-publicid="'+thisQuake.properties.publicid+'" class="overlay latest">' + thisQuake.properties.magnitude.toFixed(1) + 'M&nbsp;' + time + '</div>'
            });

            console.log('populated again', strongestQuake);
            if ( strongestQuake.properties.magnitude < thisQuake.properties.magnitude ) {
                strongestQuake = thisQuake;
                populateStrongest(strongestQuake);
            }
        }
        totalSeconds = getSeconds(thisQuake.properties.origintime);

        $('div').find('[data-publicid="' + thisQuake.properties.publicid + '"]').twinkle({
            "effectOptions": {
                "color": "rgba(0,150, 0, 0.5)",
                "radius": 80
            }
        });
        $('div').removeClass('strongest');
        $('div[data-publicid="' + strongestQuake.properties.publicid + '"]').addClass('strongest');

        $('.strongest').twinkle({
            "effectOptions": {
                "radius": 100
            }
        });
    });
}


function populateStrongest(thisQuake) {
    time = getTime(thisQuake.properties.origintime);
    $('.xcoord', '.strongest_quake').html(thisQuake.geometry.coordinates[0]);
    $('.ycoord', '.strongest_quake').html(thisQuake.geometry.coordinates[1]);
    $('.depth', '.strongest_quake').html(thisQuake.properties.depth.toFixed(0) + ' km');
    $('.publicid', '.strongest_quake').html(thisQuake.properties.publicid);
    $('.origintime', '.strongest_quake').html(time);
    $('.magnitude', '.strongest_quake').html(thisQuake.properties.magnitude.toFixed(1));
    // new line
    $('.strongest', '.strongest_quake').attr("href","https://www.geonet.org.nz/earthquake/"+thisQuake.properties.publicid);
    $('.strongest').removeClass('strongest');
}
rauwitt
  • 312
  • 2
  • 4
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/250502/discussion-on-answer-by-rauwitt-how-to-append-a-class-id-to-https-target). – Henry Ecker Dec 17 '22 at 20:08
  • Thank you so so much boss seems when i copied and pasted the index.php part it didnt do something as went all whacky looking so i just manually typed out the new span part and worked as it should maybe it added a extra char when copied ?? you are very much a life save my friend this been nagging me for like ages as this was my old script that someone stole and replaced a lot of stuff – Tim Dec 17 '22 at 22:49