I have a problem, I'm trying to dynamically add some html via javascript, and the html has a js function that's supposed to trigger when it's clicked, but I keep getting this error no matter what I do Uncaught SyntaxError: Unexpected token }
Has anyone had this problem before?
$("#addVehicle").click(function () {
vehicleQueue += '<li class="ui-state-default">' + $("#years option:selected").text() + ' - ' + $("#make option:selected").text() + ' - ' + $("#model option:selected").text() + ' - ' + $("#trim option:selected").text() + '<span><img onclick="javascript:alert("Hola");" class="removeVehicle" width="25px" src=".png"></span></li>';
$("#vehicleQueue").html('<ul id="sortable">' + vehicleQueue + '</ul>');
vehicleJson.push({
vehicleCount: vehicleCount,
vehicleYear: $("#years option:selected").text(),
vehicleMake: $("#make option:selected").text(),
vehicleModel: $("#model option:selected").text(),
vehicleTrim: $("#trim option:selected").text()
});
vehicleCount++;
});
This is my head:
<head>
<script type="text/javascript" src="view.js"></script>
<script src=".9.1.js"></script>
<script src=".10.3/jquery-ui.js"></script>
<script src="functions.js"></script>
<link rel="stylesheet" href=".10.3/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<style>
#sortable { list-style-type: none; margin: 0; padding: 0; width: 97%; }
#sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.2em; height: 18px; }
#sortable li span {width: 16px;height: 17px;display: block;text-decoration: none;position: absolute;right: 18px;top: 3px;}
</style>
</head>
I have a problem, I'm trying to dynamically add some html via javascript, and the html has a js function that's supposed to trigger when it's clicked, but I keep getting this error no matter what I do Uncaught SyntaxError: Unexpected token }
Has anyone had this problem before?
$("#addVehicle").click(function () {
vehicleQueue += '<li class="ui-state-default">' + $("#years option:selected").text() + ' - ' + $("#make option:selected").text() + ' - ' + $("#model option:selected").text() + ' - ' + $("#trim option:selected").text() + '<span><img onclick="javascript:alert("Hola");" class="removeVehicle" width="25px" src="http://haveagreatholiday./img/popup-closeButton.png"></span></li>';
$("#vehicleQueue").html('<ul id="sortable">' + vehicleQueue + '</ul>');
vehicleJson.push({
vehicleCount: vehicleCount,
vehicleYear: $("#years option:selected").text(),
vehicleMake: $("#make option:selected").text(),
vehicleModel: $("#model option:selected").text(),
vehicleTrim: $("#trim option:selected").text()
});
vehicleCount++;
});
This is my head:
<head>
<script type="text/javascript" src="view.js"></script>
<script src="http://code.jquery./jquery-1.9.1.js"></script>
<script src="http://code.jquery./ui/1.10.3/jquery-ui.js"></script>
<script src="functions.js"></script>
<link rel="stylesheet" href="http://code.jquery./ui/1.10.3/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<style>
#sortable { list-style-type: none; margin: 0; padding: 0; width: 97%; }
#sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.2em; height: 18px; }
#sortable li span {width: 16px;height: 17px;display: block;text-decoration: none;position: absolute;right: 18px;top: 3px;}
</style>
</head>
Share
Improve this question
edited May 23, 2013 at 3:14
William L.
asked May 23, 2013 at 2:54
William L.William L.
3,8869 gold badges54 silver badges72 bronze badges
8
- 2 share your plete script tag, there is an syntactical error in your script – Arun P Johny Commented May 23, 2013 at 2:56
- @ArunPJohny I added the whole script. – William L. Commented May 23, 2013 at 2:58
- This portion looks fine, check in your browser console where the error is ing from (line). The error is ing from somewhere else – Arun P Johny Commented May 23, 2013 at 2:59
- @ArunPJohny The browser console is giving the error message Uncaught SyntaxError: Unexpected token }. – William L. Commented May 23, 2013 at 3:01
- along with the message it will show the filename and line number – Arun P Johny Commented May 23, 2013 at 3:01
1 Answer
Reset to default 12Your onclick event handler has string escape problems, escape is as
onclick="alert(\'Hola\');"