Wrap Each * on a Page Using jQuery

后端 未结 5 1323
挽巷
挽巷 2021-01-06 06:55

I need to wrap each asterisks on a page with . The few things I\'ve tried don\'t work. I think what this boils down to is

5条回答
  •  梦毁少年i
    2021-01-06 07:35

    This is a bit dirty and risky (explained below), but you could try the following:

    var allHTML = $("body").html();
    allHTML = allHTML.replace(/\*/g, "*");
    $("body").html(allHTML);
    

    http://jsfiddle.net/6rDK4/

    Note: As Dogbert pointed out this might replace * characters that are within HTML tags, e.g. node attributes.

    EDIT: Bear in mind that this might reattach all the scripts you have in your body though! Try replacing body with your main container.

    EDIT2: VisioN posted a more elaborate but a lot safer solution.

提交回复
热议问题