dauzcode

contains selector

Aug 14th, 2012
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.88 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html lang=en>
  3. <head>
  4.     <title>Belajar Jquery dan Ajax</title>
  5.     <style type="text/css">
  6.         ul {
  7.             list-style: none;
  8.             padding: 0;
  9.             margin: 0;
  10.             }
  11.         .highlight {
  12.             background-color: yellow;
  13.             margin-right: 30%;
  14.             }
  15.     </style>       
  16. </head>
  17. <body>
  18.     <p><input id="search_name" type="text"  /></p> 
  19.     <ul id="names">
  20.         <li>firdaus</li>
  21.         <li>kausar</li>
  22.         <li>siti</li>
  23.         <li>sari</li>
  24.     </ul>  
  25.  
  26.     <script type="text/javascript" src="jquery.js"></script>
  27.     <script type="text/javascript">
  28.          $(document).ready(function(){
  29.            $('#search_name').keyup(function(){
  30.              search_name = $(this).val();
  31.              
  32.             $('#names li').removeClass('highlight');
  33.              
  34.             if (jQuery.trim(search_name) != ''){
  35.             $("#names li:contains('" + search_name + "')").addClass('highlight');
  36.                           }
  37.             });  
  38.            });
  39.     </script>  
  40. </body>
  41. <html>
Advertisement
Add Comment
Please, Sign In to add comment