开发者

Text replace with Jquery

开发者 https://www.devze.com 2022-12-28 14:08 出处:网络
I have to replace Text inside HTML. When I looked ViewSource of the page I found this html tag. Now I need to replace text \"Respuesta\" with \"Responder\". I am using SharePoint CEWP webpart for this

I have to replace Text inside HTML. When I looked ViewSource of the page I found this html tag. Now I need to replace text "Respuesta" with "Responder". I am using SharePoint CEWP webpart for this. What is the code I need write to replace this text?

<div><a id="ReplyLink3" href="" ONCLICK="javascript:GoToPage('');return false;" target="_self"><img id="replyButton" border="0" align="middle" alt="Respuesta" src="/_layouts/images/reply.gif">&nbsp;<NOBR><b>Respuesta</b></NOBR>&l开发者_高级运维t;/a><


You asked specifically for jQuery, so here it is in jQuery ssuming there is no other bolded text. Uses the Next Siblings Selector. Only works if there are no more <b> items as children of the div.

$(document).ready(function() {
    $("$replyButton ~ b").text("Responder");
});


Another approach using replace() JavaScript method:

$('#ReplyLink3').parent().html( $('#ReplyLink3').parent().html().replace(/Respuesta/gi,'Responder') );

You may need to optimize the selectors but this may be what you are looking for:

.replace(/Respuesta/gi,'Responder')
0

精彩评论

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