Question

This is a simple syntax question.

I have a ul saved as a variable like this:

$list = $("#city_list");

I am later removing some items from the list with this code:

$('ul#city_list li#city_' + $id).remove();

How can I do that using the $list variable I created earlier so that I get something like this:

$list.('li#city_' + $id).remove();
Was it helpful?

Solution

Use find

$list.find('li#city_' + $id).remove();

Never prefix an ID with a tag name

. So change your code to

$list.find('#city_' + $id).remove();

Read

jQuery performance Rules

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top