Text replace with Jquery

2.3k Views Asked by At

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></a><
2

There are 2 best solutions below

4
justkt On

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");
});
2
Xavi Esteve On

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')