I want to add or remove li
s to a list in javascript. For that purpose I found that I need to add data attributes and find the item with that value.
if ($('li[data-requestId=' + requestId + ']').length == 0)
{
var element = getRequestElement();
var li = document.createElement("li");
li.setAttribute("data-requestId",requestId);
li.appendChild(element);
$('#requestsUL').append(li);
}
but the first line gives this error:
Syntax error, unrecognized expression: li[data-requestId=6.22.20]