开发者

jQuery Replace Text Inside Tag with No Attributes

开发者 https://www.devze.com 2023-04-08 06:07 出处:网络
I\'m looking to replace the开发者_运维百科 text inside a <nobr> but I can\'t figure out how.

I'm looking to replace the开发者_运维百科 text inside a <nobr> but I can't figure out how.

It would be easy if I could do:

$('nobr:contains("Due")').replace('Due Date');

but there's another <nobr> that has the word "Due" in it and I don't want that affected.

What's the simplest way to find the <nobr> that's exactly equal to "Due" and replace it with "Due Date"?


You could filter all the nobr elements to eliminate any whose text is not equal to "Due":

$("nobr").filter(function() {
    return $(this).text() === "Due";
}).text("Due Date");

Here's a working example.

0

精彩评论

暂无评论...
验证码 换一张
取 消