Managing a compact to-do list where you have the ability to add new tasks and when clicking on an item, it should toggle between two classes while removing one.
<ul id="myUL" class="todoList">
<li class='todoList card border-primary'>my li</li>
</ul>
This snippet shows the JavaScript code responsible for toggling classes:
$( "#myUL" ).children().on("click",function() {
$( this ).toggleClass( "checked" );
$( this ).toggleClass( "border-primary" );
$( this ).toggleClass( "border-success" );
});
The script is included after bootstrap.min and jquery-3.3.1.min files as they are dependencies for Bootstrap components.
However, there seems to be an issue with the code only functioning on the first element. How can this be resolved?