A Web Design Community curated by Chris Coyier

Code Snippets Gallery

Code Snippets > jQuery > Search/Replace Submit one!

Search/Replace

jQuery(function () {
    jQuery(":contains(FIND)").not(":has(:contains(FIND))").each(function () {
        var that = $(this),
            html = that.html(); 

        html = html.replace(/(\(FIND:.*?\))/g, "REPLACE-WITH");
        that.html(html);
    });
});

Reference URL

4 Responses

  1. That is so over-complicated.

Leave a Comment

Remember:
  • Be nice.
  • Wrap multiline code in <pre> and <code> tags and escape it first (turn <'s into &lt;'s).
  • You may use regular HTML stuff like <a href="">, <em>, and <strong>
* This website may or may not contain any actual CSS or Tricks.