简体   繁体   中英

How do I remove an asterisk (*) from a the text contained with a <td> using jquery?

I've got a table column definition that looks like this:

<td class="dvRequiredField validationFailed">
    *&nbsp;
    <input name="ctl00$MainContent$dvCustomer$ctl04" type="text" title="First Name" class="validationFailed">
    &nbsp;Required Field.
</td>

How do remove the "asterisk" (or in a sense replace it with '') using jquery?

I've tried the following:

$('td.validationFailed').each(function () {
    $(this)[0].innerHTML = $(this)[0].innerHTML.replace(/\*/g, '');
});

It does not work. It replaces/removes the text value of my input control.

Thanks, JohnB

DEMO

$('td.validationFailed').contents().filter(function() { 
    return this.nodeType == 3 && this.wholeText.indexOf('*') > -1; 
})
.remove();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM