Wednesday, August 27, 2014

Remove Same Strings Using JQuery

This script is used to remove duplicates entry for string.remove() method is used to remove the strings.




Live DemoDownload Script


Need library file to perform this action.Please copy and Paste below library file.
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.0.js"></script>

Jquery Function

<script type='text/javascript'>
        $(window).load(function(){
        var txtString = {};
        $('p').each(function() { //Get all strings using p tag
            var txt = $(this).text();
            if (txtString[txt]){
                $(this).remove(); //remove same string
            }else{
                txtString[txt] = true;
                }
        });
        });

    </script>

HTML Code

<p>Java</p>
  <p>Joomla</p>
  <p>PHP</p>
  <p>CSS</p>
  <p>PHP</p>
  <p>Joomla</p>
  <p>Java</p>


Please share your comments and feedback.Thanks.Please subscribe my updates via email.

No comments:

Post a Comment