I am trying to append a new list item based on a condition using jquery. For reference the page is a Wordpress page and i have been able to implement serval jquery scripts using same format.
Here is the sample HTML.
<div class = "bag" id = "bag" style="width: 100%; padding: 0 0 0 5px; float: left;">
<ul id = "clubsli" name = "clubsli" class = "clubsli">
I dynamically create a li
with "n" values and want to append a new li
to the end of this list using JavaScript/jQuery script.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
function addClub() {
$roleint = 2613;
$count = $("#clubsli li").length - 1;
if ($roleint == 2613) {
if ($count < 100) {
$("#bag ul").append('<li>$roleinit</li>');
};
};
};
});
</script>
No matter what I do I get the following Unexpected token ILLEGAL
error that seems to not like the "<" in the list element.
Here is the error I receive.
I've tried appending a non-li
and can without fail and tried "appendTo" but get same error on the "<".
` element in the console come from, that doesn't appear anywhere in the posted source?)
– Matt Gibson Apr 03 '16 at 18:15` but i don't know why or how to prevent it.
– oldnewbe Apr 03 '16 at 18:21