Forum

jQuery - show or hi...
 
Notifications
Clear all

jQuery - show or hide elements based on text input

1 Posty
1 Users
0 Reactions
665 Widok
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();
});

 

 

Odpowiedź

Author Name

Author Email

Your question *

 
Preview 0 Revisions Saved
Share: