开发者

jQuery Replace Text Inside Tag with No Attributes

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜