0

I've a php code, it prints some text. But I need to replace "n" character with "N" by JavaScript (without editing php code). In everywhere (All texts). How can I do it? Thanks ...

PS: I was creating another topic (#4459901), but this topic is different!

3 Answers 3

1

Before I write this: I don't recommend it. Doing this before outputting to the browser would be your best bit. It's also not great for single characters because it will replace all instances of n with N (i.e. <span> will become <spaN>.

document.body.innerHTML= document.body.innerHTML.replace(/n/g, "N");

Example: http://jsfiddle.net/jonathon/x4akZ/

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, but If I want to replace only texts in <span>, what can I do?
0

Use:

replaced = str.replace(/n/g, "N");

Comments

0

You have just to use the replace function, and after your regex, ou must uso /g which means that you want to replace all chars.

"non".replace(/n/g, 'N')

2 Comments

it's correct, but I don't print any text with javascript! I need replace all texts in body.
you have to add it to a variable like: var replaced = str.replace(/n/g, 'N')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.