Forum

jQuery - show or hi...
 
Notifications
Clear all

jQuery - show or hide elements based on text input

   RSS

0
Topic starter

example

1 Answer
0
Topic starter

html

<input type="text" id="place-search" />
 <ul>
		<li class="place-object">
			<p>Place 1</p>
		</li>
		<li class="place-object">
			<p>Place 2</p>
		</li>
		<li class="place-object">
			<p>Place 3</p>
		</li>
		<li class="place-object">
			<p>Place 4</p>
		</li>
 </ul>

jquery

$("#place-search").keyup(function (){
	let query = $(this).val();
	let pattern = new RegExp(query,"i");

	$('.place-object').filter(function() {
		if(!$("p",this).text().match(pattern))
			return true;
		$(this).show();
	}).hide();
});

 

 

This post was modified 2 tygodnie temu by mrmucha

Odpowiedź

Author Name

Author Email

Your question *

 
Preview 0 Revisions Saved
Share: