Search code examples
javascriptjqueryhide

Replace last 5 character from username with x


I have to hide the last 5 characters of the username . Below is the code

<ul>
<li>
            </dl>
                <dl>
                <dt>Username:</dt>
                <dd id="up-d-username">AZRT435231
                </dd>
            </dl>
</li>
</ul>

I need to replace the last 5 characters with a "X" so the output should be AZRT4XXXXX . Also is it possible that the user do not see this name from the source of the page using tools like firebug?


Solution

  • You can do it this way.

    Live Demo

    txt = $.trim($('#up-d-username').text());
    $('#up-d-username').text(txt.substring(0, txt.length - 5) + "XXXXX");