Home » Javascript » Converting Javascript Alert Into HTML

Converting Javascript Alert Into HTML

Posted by: admin November 1, 2017 Leave a comment

Questions:
<script> $.getJSON("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_month.geojson", function(json) 
      {console.log(json);  var newString = JSON.stringify(json, null, 0)var obj = JSON.parse(newString);alert(obj.features.length) })</script>

A helpful wrote some code which brought up an alert box on my website www.livehazards.com.

How do I convert this line of code into html so I can display that same sentence in my sidebar

Thanks in advance

 alert("There have been  " + obj.features.length + "  Earthquakes in the last month");
Answers:

With jQuery (since it looks like you’re using jQuery there):

$("#elementID").text("There have been " + obj.features.length + " Earthquakes in the last month");

Where elementID is the ID of the element you want the text inside of.