locked
removing text using jquery RRS feed

  • Question

  • User-73514677 posted

    Hi,

    I have a column which shows value as abc.test@xyz.com , Can jquery be used to show only "abc.test" ? How to achieve this for all records.

    Thanks

    Friday, August 26, 2016 10:33 AM

Answers

  • User-491950272 posted

    Greetings,

    you can do this by writing:

    $('textbox').removeByContent('abc.test');

    2nd solution:

    $('textbox').contains('abc.test').remove();​

    3rd solution:

    $('textbox').filter(function() {
        return $(this).html().indexOf('abc.test') != -1;
    }).remove();​

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 26, 2016 11:17 AM
  • User-1142886626 posted

    Hi venkatzeus,

    I have a column which shows value as abc.test@xyz.com , Can jquery be used to show only "abc.test" ? How to achieve this for all records.

    You could use JavaScript String split() Method achieve this.

    Code below is for your reference:

    <script type="text/javascript">
            $(function () {
                $("p").each(function () {
                    var txt=$(this).text().split("@")[0];
                    $(this).text(txt);
    
                })
            })
        </script>
    <body>
        <div>
            <p>abc.test@xyz.com</p>
            <p>q.test@xyz.com</p>
            <p>w.test@xyz.com</p>
            <p>e.test@xyz.com</p>
            <p>r.test@xyz.com</p>
        </div>
    </body>
    

    Screenshot:

    Best Regards,

    Ailleen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 28, 2016 1:26 PM
  • User445449386 posted

    You can also use subtstring function

    var oldstring = "abc.test@xyz.com";
    var newstring = oldstring.substring(0,oldstring.indexOf("@"));
    alert(newstring);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 2, 2016 6:59 AM

All replies

  • User-491950272 posted

    Greetings,

    you can do this by writing:

    $('textbox').removeByContent('abc.test');

    2nd solution:

    $('textbox').contains('abc.test').remove();​

    3rd solution:

    $('textbox').filter(function() {
        return $(this).html().indexOf('abc.test') != -1;
    }).remove();​

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 26, 2016 11:17 AM
  • User-1142886626 posted

    Hi venkatzeus,

    I have a column which shows value as abc.test@xyz.com , Can jquery be used to show only "abc.test" ? How to achieve this for all records.

    You could use JavaScript String split() Method achieve this.

    Code below is for your reference:

    <script type="text/javascript">
            $(function () {
                $("p").each(function () {
                    var txt=$(this).text().split("@")[0];
                    $(this).text(txt);
    
                })
            })
        </script>
    <body>
        <div>
            <p>abc.test@xyz.com</p>
            <p>q.test@xyz.com</p>
            <p>w.test@xyz.com</p>
            <p>e.test@xyz.com</p>
            <p>r.test@xyz.com</p>
        </div>
    </body>
    

    Screenshot:

    Best Regards,

    Ailleen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 28, 2016 1:26 PM
  • User445449386 posted

    You can also use subtstring function

    var oldstring = "abc.test@xyz.com";
    var newstring = oldstring.substring(0,oldstring.indexOf("@"));
    alert(newstring);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 2, 2016 6:59 AM