Javascript create elements in two places -


how need write have elements created in 2 places?

here code.

i have tried using document.getelementsbyname , document.getelementsbyclassname , neither of them work.

html

<p style="display:block;" class="coords"></p> 

javascript

function getlocation() {     if (navigator.geolocation) {         navigator.geolocation.getcurrentposition(showposition);     } else {         x.innerhtml = "geolocation not supported browser.";     } }  function showposition(position, coords) {     var places = document.getelementsbyclassname(coords);     (var = 0; < places.length; i++)     {         places[i].innerhtml = "<input type='text' name='lat' id='lat' value='" + position.coords.latitude + "'>" +             "<input type='text' name='lon' id='lon' value='" + position.coords.longitude + "'>";     } } 

after calling getelementsbyclassname must use loop update each of them.

function showposition(position) {     var places = document.getelementsbyclassname("coords");     (var = 0; < places.length; i++) {         places[i].innerhtml="<input type='text' name='lat' id='lat' value='" + position.coords.latitude + "'>" +                             "<input type='text' name='lon' id='lon' value='" + position.coords.longitude + "'>";     } } 

Comments