Created
October 31, 2014 18:52
-
-
Save Microsofttechies/7f4ad8817d6346138165 to your computer and use it in GitHub Desktop.
jQuery Remove Duplicate Values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html xmlns="http://www.w3.org/1999/xhtml"> | |
| <head> | |
| <title></title> | |
| <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> | |
| <script> | |
| $(document).ready(function () { | |
| $('.submitButton').click(function (e) { | |
| var startTime = new Date(); | |
| var seen = {}; | |
| $('ul li').each(function () { | |
| var txt = $(this).text(); | |
| if (seen[txt]) | |
| $(this).remove(); | |
| else | |
| seen[txt] = true; | |
| }); | |
| var endTime = new Date(); | |
| var difference = endTime – startTime; | |
| alert("document.ready time: " + difference + " milliseconds"); | |
| return false; | |
| } | |
| ); | |
| }); | |
| </script> | |
| </head> | |
| <body> | |
| <div style="width: 100px"> | |
| <ul> | |
| <li style="background-color: Red">A</li> | |
| <li style="background-color: Red">B</li> | |
| <li style="background-color: Orange">B</li> | |
| <li style="background-color: Red">C</li> | |
| <li style="background-color: Orange">C</li> | |
| <li style="background-color: Yellow">C</li> | |
| <li style="background-color: Red">D</li> | |
| </ul> | |
| </div> | |
| <input id="bntSubmit" type="submit" value="submit" class="submitButton" /> | |
| </body> | |
| <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.js"> | |
| </script> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment