My Jquery code is recieving following error:
Uncaught SyntaxError: Unexpected token ;
Here is my jquery code:
<script type="text/javascript">
$(function() {
$('#CustomButton').click(function() {
$('#CustomPickedTable tbody').append(
$('<tr/>', {
click: function() {
$(this).remove()
},
html: $("<td />", {
html: $("#CustomQuestionText").val(),
'data-attr-id': 5
})
})
);
return false;
});
}); // <--- This line recieves the error
</script>
This is my mark up for this jquery code:
<table id="CustomPickedTable" class="box-style2">
<thead>
<tr>
<th>Valda frågor</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<br />
<p>Lägg till egen fråga</p>
<div class="editor-field">
@Html.TextAreaFor(model => model.CustomQuestionText, new { @class = "selectstyle", @id = "CustomQuestionText" })
@Html.ValidationMessageFor(model => model.CustomQuestionText)
</div>
<div>
<p><input type="button" id="CustomButton" value="Lägg till" /></p>
</div>
</div>
what may cause this error how can I fix it?
Thanks in advance
second last line after semicolon there is a special char i just remove this now try again with this code
$(function() {
$('#CustomButton').click(function() {
$('#CustomPickedTable tbody').append(
$('<tr/>', {
click: function() {
$(this).remove()
},
html: $("<td />", {
html: $("#CustomQuestionText").val(),
'data-attr-id': 5
})
})
);
return false;
});
}); // <--- This line recieves the error
When I copy the code to notepad++ I get: (note the ?)
$(function() {
$('#CustomButton').click(function() {
$('#CustomPickedTable tbody').append(
$('<tr/>', {
click: function() {
$(this).remove()
},
html: $("<td />", {
html: $("#CustomQuestionText").val(),
'data-attr-id': 5
})
})
);
return false;
});?
}); // <--- This line recieves the error
Fixed it and changes function() to document.ready for clarity:
$(document).ready(function() {
$('#CustomButton').click(function() {
$('#CustomPickedTable tbody').append(
$('<tr/>', {
click: function() {
$(this).remove()
},
html: $("<td />", {
html: $("#CustomQuestionText").val(),
'data-attr-id': 5
})
})
);
return false;
});
});
Contains some illegal character in second last line. Removed it and it worked.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.