<!DOCTYPE html> <html> <head> <title>Try jQuery Online</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script> $(document).ready(function() { $("em").addClass("selected"); $("#myid").addClass("highlight"); }); </script> <style> .selected { color:red; } .highlight { background:yellow; } </style> </head> <body> <em title="Bold and Brave">This is first paragraph.</em> <p id="myid"></p> <script> var xml = "<?xml version='1.0' encoding='UTF-8'?><gpx creator='StravaGPX iPhone' xmlns:xsi='https://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='https://www.topografix.com/GPX/1/1 https://www.topografix.com/GPX/1/1/gpx.xsd' version='1.1' xmlns='https://www.topografix.com/GPX/1/1'> <metadata> <time>2019-01-27T13:51:59Z</time> </metadata> <trk> <name>Afternoon Ride</name> <type>1</type> <trkseg> <trkpt lat='49.9542350' lon='18.9043470'> <ele>266.2</ele> <time>2019-01-27T13:51:59Z</time> </trkpt> <trkpt lat='49.9542760' lon='18.9043830'> <ele>266.4</ele> <time>2019-01-27T13:52:01Z</time> </trkpt> <trkpt lat='49.9542350' lon='18.9043210'> <ele>266.5</ele> <time>2019-01-27T13:52:24Z</time> </trkpt> <trkpt lat='49.9542080' lon='18.9043140'> <ele>266.5</ele> <time>2019-01-27T13:52:25Z</time> </trkpt> </trkseg> </trk></gpx>"; xmlDoc = $.parseXML( xml ); $xml = $( xmlDoc ); $(xml).find('trkpt').each(function(){ $ele = $(this).find('ele') console.log($(this).attr('lat') + " " + $(this).attr('lon') + " " + $ele.text() ); }); $time = $xml.find( "trkpt" ) $ele = $xml.find( "ele" )[0]; // Append "RSS Title" to #someElement $( "#myid" ).append( $time); $( "#myid" ).append( " "); $( "#myid" ).append( $ele); </script> </body> </html>
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more