I have a list which is dynamically created like this:
inner += "<li class='linkstyl'> <a href='#"+tot+"' id='a"+tot
+ "' style='text-decoration:none' onclick='addpoint("
+ results[0].geometry.location.lat()+","
+ results[0].geometry.location.lng()+")'> "
+ results[0].formatted_a开发者_运维知识库ddress+"</a></li>"
Then I am using:
$("#showaddress").html(inner); // to insert it inside <ul> with id as showaddress .
My problems is that when I try to getElementById
of the this dynamically created elements
it returns me a null value.
That code works fine. Perhaps you are trying to use getElementById()
before the ajax request completes. At that point the elements won't be on the page still. Otherwise perhaps your tot
variable doesn't contain what you think it does.
Try checking those two things over.
javascript is asynchronous. May be the elements are not yet available when you are trying to get them. Try the selector in the callback itself where you get the response from the geocoder.
精彩评论