views:

171

answers:

2

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  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");
});
justkt
Do you any body know about Sharepoint? How can I put this code sharepoint page using CEWP?
James123
Are you trying to statically update the word Respuesta (permanently for all time), or do it dynamically for some reason? If the former, just edit the page with CEWP. If the latter, then you need to find the Head of your webpage and add a script or external script.
justkt
I want permanently for all time. How can I find Head of the web page and your script please, direct me.
James123
@James123 - doesn't sound like you want to use jQuery. Instead, it sounds like you want to edit the HTML - is that correct? If so, just remove Respuesta and write Responder.If you aren't familiar with editing using HTML, looks like there are some good CEWP tutorials out there if you Google.
justkt
+1  A: 

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')
XaviEsteve
Seems like a better solution than mine.
justkt
You're missing the inner `parent()`. Right now, it is replacing with only the content of `#ReplyLink3`, excluding the element itself.
patrick dw
I've updated the code. Thanks Patrick
XaviEsteve