Q:

Find elements containing specific value within custom tag with space-separated values

Imagine I have something like this:
<li tags="1 3 "></li>
<li tags="2 3 "></li>
<li tags="4 "></li>

Tags are separated by space. What in my head is to find <li>s by tags that are put in as custom attribute in order not to make another query just to find projects with the tag selected.
Is there anyway to for example to find all <li>s with the tag 3 and the result to be something like this :
result = <li tags ="1 3 "></li><li tags ="2 3 "></li>
so I can put it in the container like $('.container').html(result);
Or maybe a better way: find the <li>s that does not have that tag and add css property of display: none
I think the latter is more efficient.

A:

Yes, you can use ~=: to find li elements, that have '3' in tags attribute value:
$('li[tags~=3]');

And use :not() selector to find elements, that don't have '3', and hide them:
 $('li:not([tags~=3])').hide();

If you want to target li with specific class, use li.class.

