title: Public IP address as variable in JavaScript/HTML
body: <p>How can I get a public IP address as a; <strong><em><code>var ip = $("#ip")</code></em></strong> ?</p>
  
  <p>I hope to achieve is to put a public IP address into a var.</p>
  
  <p>So far I have this:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  var yourip = document.getElementsByTagName("body")[0].ip
  window.alert("your IP is" + yourip);
  &lt;/script&gt;
  &lt;body&gt;
  &lt;span id="ip"&gt;&lt;/span&gt;
  &lt;/body&gt;
  &lt;script type="text/javascript"&gt;
  $.getJSON("http://jsonip.com?callback=?", function (response) {
  $("#ip").text(response.ip);
  });
  &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>