admin管理员组文章数量:1322531
Getting Uncaught TypeError: Cannot set property 'innerHTML' of null. How to fix it.
$(window).load(function() {
document.getElementById("id_city").innerHTML = ('<option>Select a City</option>');
var selected_state = $('#id_state').val();
var selected_city = $('#selected_city').val();
var data = 'state='+selected_state + '&selected_city='+selected_city;
var url = $('#url').val();
$.ajax({
type:"POST",
url:url,
data:data, // multiple data sent using ajax
success: function (response) {
document.getElementById("id_city").innerHTML=response;
}
});
});
Getting Uncaught TypeError: Cannot set property 'innerHTML' of null. How to fix it.
$(window).load(function() {
document.getElementById("id_city").innerHTML = ('<option>Select a City</option>');
var selected_state = $('#id_state').val();
var selected_city = $('#selected_city').val();
var data = 'state='+selected_state + '&selected_city='+selected_city;
var url = $('#url').val();
$.ajax({
type:"POST",
url:url,
data:data, // multiple data sent using ajax
success: function (response) {
document.getElementById("id_city").innerHTML=response;
}
});
});
Share
Improve this question
asked Jan 12, 2017 at 12:47
Rupinder KaurRupinder Kaur
3176 silver badges22 bronze badges
1
-
be insure
id_city
is correct and element rendered on page – Sanjay Nishad Commented Jan 12, 2017 at 12:49
5 Answers
Reset to default 3This error means in this line:
document.getElementById("id_city").innerHTML
you have
document.getElementById("id_city") = null
Please make sure you have any markup with id parameters set to "id_city"
Make sure you are having an element with that id on the page. If possible please share the HTML for better result.
Example: <select id="id_city"></select>
The error line is document.getElementById("id_city").innerHTML and the reason could be
- the element not in html
- the script is called before the element is bound to html
try placing the script at the bottom of the page
you can use jquery method
$("#id_city").html(response);
document.getElementById("id_city").innerHTML=response;
to
document.getElementById("id_city").html(response);
or
$('#id_city').html(response);
本文标签: javascriptCannot set property 39innerHTML39 of null in JqueryStack Overflow
版权声明:本文标题:javascript - Cannot set property 'innerHTML' of null in Jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742109044a2421159.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论