In jQuery How to Remove specific text from an element?

User avatar
RachelPeene
Posts: 6
Joined: Sat Oct 01, 2016 12:13 pm

In jQuery How to Remove specific text from an element?

Fri Mar 29, 2019 3:16 am

If you want to remove specific text inside an element you can do this by:

Example:
Name: John Doe
to be just,
Joe Doe
You can try this:
$(':contains("Name:")').each(function(){
$(this).html($(this).html().split("Name:").join(""));
});
This removes any occurrence of "By:" in any element. If you want to target specific type of elements, simply change $(':contains("Name:")') to include whatever selector suits you.

or if,

You're using table for example. Try this

Code: Select all

<table class="Name">
    <tbody>
        <tr>
            <td>
                <table>
                    <tbody>
                        <tr>
                            <td><i>Name:John Doe</i>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>
    </tbody>
</table>
<table class="Name">
    <tbody>
        <tr>
            <td>
                <table>
                    <tbody>
                        <tr>
                            <td><i>Name:John Doe</i>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>
    </tbody>
</table>
Do this,
$('table.Name tbody tr td table tbody tr td i:contains("Name:")').each(function(){
$(this).html($(this).html().split("Name:").join(""));
});


Return to “WEB DESIGN, PHP, HTML”

Links

In total there are 6 users online :: 0 registered, 0 hidden and 6 guests
Registered users: No registered users
Most users ever online was 33 on Sat Mar 09, 2019 8:21 pm
Total posts 489
Total topics 371
Total members 70
Our newest member Mirasoida
No birthdays today