javascript - Cannot set innerHTML or $(this).val successfully in AJAX function -
using ajax have retrieved json info but, during function, cannot display text in relevant div.
the code works right bottom, can see using console, if set placeholder text in div "place", placeholder text stays same right end of function.
$.each(data, function(i,item){ if(i===0){ var placehtml='<h2>'+item.name+'</h2>' + '<p>where can <br>' + 'a pint of <em>'+item.pint+'</em> only<br>' + '<span>£'+item.cost+'!</span></p>'; window.localstorage.setitem("placename", item.name); window.localstorage.setitem("placeloc1", item.location); window.localstorage.setitem("placeloc2", item.location2); window.localstorage.setitem("placeemail", item.email); window.localstorage.setitem("placenumber", item.number); console.log("data saved"); document.getelementbyid("place").innerhtml = placehtml; console.log("data placed:"); console.log(placehtml); $("#loadtext").fadeout(); $('#place').fadein(); homecoming false; } });
i have tried replacing document.getelementbyid("place").innerhtml = foo
$("#place").val(foo)
no luck.
the div has values id="place"
, class="place"
.
document.getelementbyid("place").innerhtml = placehtml;
should be
document.getelementbyid("place").innerhtml = placehtml;
to jquery
$("#place").html(placehtml)
val
set value of input field, alter inner html jquery want utilize html()
function
javascript jquery html ajax
No comments:
Post a Comment