Home javascript Find and replace text in the whole document

Find and replace text in the whole document

Author

Date

Category

Tell me how to find and replace the text in the whole document?
For example

& lt; div & gt; QWEQWE & LT; / DIV & GT;
& lt; img scr = "img / qweqwe.jpg" & gt;

Change QWeqWe on ASDF


Answer 1, Authority 100%

$ ("span, p, div"). Each (function () {
  var text = $ (this) .text ();
  text = text.replace ("QWeqwe", "ASDF");
  $ (this) .text (text);
});

We take place on all SPAN , P and DIV and change the text in them.

Attributes, of course, do not touch. Therefore, in IMG you have the name of the file and remain the same (I hope you do not have the same attributes and tags to rename).

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions