javascript - Easy filter from HTML divisions with jQuery -


i'm trying change background-color css property of item matches input criteria given:

my html:

<!doctype html> <html> <meta charset="utf-8"> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <link rel="stylesheet" type="text/css" href="plantilla.css"> <script src="plantilla.js"></script> <head> <title>plantilla</title> </head> <body>     <input type="text" id="input" class="input" value="" />     <div id="main" class="main">         <div id="header">main</div>         <div id="global1" class="global">             global1             <div id="small11" class="small">aaaaaa</div>             <div id="small12" class="small">aaabaa</div>             <div id="small13" class="small">aaacaa</div>             <div id="small14" class="small">aaadaa</div>             <div id="small15" class="small">aaaeaa</div>         </div>         <div id="global2" class="global">             global2             <div id="small21" class="small">abcdef</div>             <div id="small22" class="small">fedcba</div>             <div id="small23" class="small">facbde</div>             <div id="small24" class="small">decfab</div>             <div id="small25" class="small">bacfed</div>         </div>         <div id="global3" class="global">             global3             <div id="small31" class="small">eeeeee</div>             <div id="small32" class="small">eabdc</div>             <div id="small33" class="small">bcdae</div>             <div id="small34" class="small">dcbea</div>             <div id="small35" class="small">eadcb</div>         </div>         <div id="global4" class="global">             global4             <div id="small41" class="small">decab</div>             <div id="small42" class="small">baced</div>             <div id="small43" class="small">becad</div>             <div id="small44" class="small">daceb</div>             <div id="small45" class="small">cedab</div>         </div>         <div id="global5" class="global">             global5             <div id="small51" class="small">cadeb</div>             <div id="small52" class="small">cadeb</div>             <div id="small53" class="small">cedab</div>             <div id="small54" class="small">eadcb</div>             <div id="small55" class="small">aebdc</div>         </div>     </div> </body> </html> 

so if in input "user" enters: "aebdc" should change #small55 background-color yellow. if in input there an: "a" should change background-color of of divs. if none matches criteria, none changed.

you can filter based on text content of div

$('#input').on('input', function() {      var value = this.value;      $('.global div').css('background', '').filter(function() {         return $(this).text().indexof(value) !== -1;     }).css('background', 'red'); }); 

fiddle

if need case-insensitive search, add tolowercase both value , text.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -