admin管理员组文章数量:1430077
I'm getting a SyntaxError: Parse Error when my browser runs the following code for an iPhone:
if (window.innerWidth && window.innerWidth <= 480) {
$(document).ready(function(){
$('#usernav ul').addClass('hide');
$('#usernav').append('<div class="leftButton"
onclick="toggleMenu()">Menu</div>');
});
function toggleMenu() {
$('#usernav ul').toggleClass('hide');
$('#usernav' .leftButton').toggleClass('pressed');
}
}
I'm new to all of this (programming, programming languages, etc.) but I'm wondering if this error is caused because I'm viewing my site in a browser.
I've noticed that when I drag my browser's window so the viewing width decreases, my styles degrade as the width decreases. Most sites (including SO it seems) don't allow this degradation in a browser, so I guess my questions are:
- What's the error in my JavaScript
- What are the best ways to stop my browser from degrading?
Hopefully that makes sense. Maybe the degradation isn't related to the JavaScript but since it's relevant I figured I'd ask.
EDIT: I've updated the code to close off the append
but I'm still getting errors at the $('#usernav').append('<div class="leftButton"
line. My IDE says "unterminated string literal".
I'm getting a SyntaxError: Parse Error when my browser runs the following code for an iPhone:
if (window.innerWidth && window.innerWidth <= 480) {
$(document).ready(function(){
$('#usernav ul').addClass('hide');
$('#usernav').append('<div class="leftButton"
onclick="toggleMenu()">Menu</div>');
});
function toggleMenu() {
$('#usernav ul').toggleClass('hide');
$('#usernav' .leftButton').toggleClass('pressed');
}
}
I'm new to all of this (programming, programming languages, etc.) but I'm wondering if this error is caused because I'm viewing my site in a browser.
I've noticed that when I drag my browser's window so the viewing width decreases, my styles degrade as the width decreases. Most sites (including SO it seems) don't allow this degradation in a browser, so I guess my questions are:
- What's the error in my JavaScript
- What are the best ways to stop my browser from degrading?
Hopefully that makes sense. Maybe the degradation isn't related to the JavaScript but since it's relevant I figured I'd ask.
EDIT: I've updated the code to close off the append
but I'm still getting errors at the $('#usernav').append('<div class="leftButton"
line. My IDE says "unterminated string literal".
-
Why don't you create the element with jQuery and get rid of the inline event handler?
$('<div />', {'class': "leftButton", text: 'Menu', click: toggleMenu}).appendTo('#usernav');
– Felix Kling Commented Sep 23, 2011 at 0:27
3 Answers
Reset to default 2Javascript can end lines with semicolons OR newlines. When you put in a new line, you ended your statement early. Put the statement on one whole line.
The problem is here:
$('#usernav').append('<div class="leftButton"
onclick="toggleMenu()">Menu</div>;
You're not closing .append('
. You want this:
$('#usernav').append('<div class="leftButton" onclick="toggleMenu()">Menu</div>');
$('#usernav').append('<div class="leftButton" onclick="toggleMenu()">Menu</div>;');
I guess you forgot to close the function append()
with the bracket and the semicolon. :)
本文标签: javascriptHelp resolving SyntaxError Parse errorStack Overflow
版权声明:本文标题:javascript - Help resolving SyntaxError: Parse error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745457852a2659186.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论