text replace with jquery

后端 未结 3 630
醉酒成梦
醉酒成梦 2021-01-28 16:28

So im using jquery to search and replace certain text in my html page. Which is:

function offon(){
  $(\"#sidebar li\").each(function(){
     $(this).html($(this         


        
相关标签:
3条回答
  • 2021-01-28 17:02

    We might need to see more markup to make sure the selector is correct. As well, as Boushley mentions, the timing might be such that the tooltips are generated (or added) after your jQuery executes.

    0 讨论(0)
  • 2021-01-28 17:06

    You need to do the same text replace before you attach the data to the google map. Or when you attach the data to the google map.

    0 讨论(0)
  • 2021-01-28 17:07

    I see from the comments you figured this out, just a bit of an optimized version here:

    function offon(){
      $("#sidebar li").html(function(i, h){
         return h.replace(/Off Premise/, "Liquor Store")
                 .replace(/On Premise/, "Bar/Restaurant");
      });
    }
    

    You can test it here

    .html() can take a function, and doesn't need to create unnecessary jQuery objects (and .html() calls) along the way, this will result in a lot of saved CPU cycles all around.

    0 讨论(0)
提交回复
热议问题