[Answer]-Django/JQuery Syntax Error: I don't know why I am getting this error

1👍

item.before($("li", result));

Should be

item.before($("li", $(result)));

Or, maybe

item.before($("li"), result));

Depends on what are you trying to achieve and your HTML structure.

The source of error is that second parameter to $ should be a DOM context or JQuery element to use as an element search tree top (i.e. only descendants are searched). With your code, you are trying to find lis under the htmlString, which is obviously an error. So, most likely it’s just a missing or misplaced ).

You should stick with first if you are trying to find lis inside the returned string. Use second if you are about to insert the returned html before lis.

👤J0HN

Leave a comment