Often ( too often ) I get this error in chrome console. I really can't find any syntacs error in my javascript code
When I try to locate where this error happen in google chrome, it always shows this:
It shows that error is on the beginning of the file ( somewhere around DOCTYPE ). Is this just that chrome doesn't show more infos or I messed up with inclusion of the files somewhere? ( or maybe even syntacs? ). Either way, I can't locate it with help of debug console
this is global.js:
(function() {
$("#btadd").click(function() {
$(".newlist").slideUp();
return false;
});
})();
this is html:
<div class="newlist" style="display:none">
<h4>Title: <input type="text"/></h4>
</div>
<br />
<a href="javascript:void()" id="btadd"><span>Add New</span></a>
Often ( too often ) I get this error in chrome console. I really can't find any syntacs error in my javascript code
When I try to locate where this error happen in google chrome, it always shows this:
It shows that error is on the beginning of the file ( somewhere around DOCTYPE ). Is this just that chrome doesn't show more infos or I messed up with inclusion of the files somewhere? ( or maybe even syntacs? ). Either way, I can't locate it with help of debug console
this is global.js:
(function() {
$("#btadd").click(function() {
$(".newlist").slideUp();
return false;
});
})();
this is html:
<div class="newlist" style="display:none">
<h4>Title: <input type="text"/></h4>
</div>
<br />
<a href="javascript:void()" id="btadd"><span>Add New</span></a>
Share
Improve this question
edited Feb 16, 2013 at 17:16
Alexim
asked Feb 16, 2013 at 17:10
AleximAlexim
811 silver badge5 bronze badges
3
- 1 You'll need to post some code or an example. – j08691 Commented Feb 16, 2013 at 17:12
- 3 The SyntaxError won't be your DOCTYPE - go through your JavaScript – hohner Commented Feb 16, 2013 at 17:13
- code added , this is basically all I have – Alexim Commented Feb 16, 2013 at 17:18
2 Answers
Reset to default 5I had a similar problem. The error could also e from
javascript:void();
which should actually be
javascript:void(0);
You can reproduce this error in your console with
void()
Change this:
(function() {
$("#btadd").click(function() {
$(".newlist").slideUp();
return false;
});
})();
to this:
$(function () {
$("#btadd").click(function () {
$(".newlist").slideUp();
return false;
});
});
Or move your existing JavaScript to the end of the body. You created a self-invoking anonymous function that's executing before the elements it applies to have been loaded. This would work fine once the DOM is fully loaded, but since it's in the head of your document it runs too early. By using the example I showed you you're using jQuery's document ready event to run the code.