简体   繁体   中英

jQuery replaceWith not working in Firefox 42

I've been using the following code as my jQuery jumpoff point for replacing content on some sites. On every site I've ued it, this bit of jQuery has worked without problem... until now.

For some reason, my replaceWith isn't working in Firefox on this one site and I can't seem to track down the reason.

I've du around here looking for the answer and, while I've found other cases of replaceWith not working, none seem to point me in the right direction to figuring out/fixing my particualr issue.

So, below is my bit of script and, all I want to do is replace phone numbers in paragraphs and in the header top right area. Again, it's working in Chrome, Edge, and Safari but, no go in Firefox.

Oh, a link to the site I'm having the problem on: http://greenvilledisabilitylawyer.net/

jQuery(function($) {
    // NUM SWAP IN DIV
    $("li.menu-item-33").replaceWith(
        "<li id='menu-item-33' class='numbertop menu-item menu-item-type-custom menu-item-object-custom menu-item-33'><a href='tel:8643004994'> Free Consultation (864) 300-4994</a></div>"
    );
    // NUM SWAP IN PARAGRAPH
    $('p').not('.site-title').each(function() {
        var num1 = $(this).text().replace(/235-0886/g,
            "300-4994");
        $(this).text(num1);
    });
    // NUM SWAP IN PARAGRAPH
    $('p').not('.site-title').each(function() {
        var num2 = $(this).text().replace(/369-7200/g,
            "210-3290");
        $(this).text(num2);
    });
});

Not sure why it is not working in your side.Can you please check the console. Here is a snippet that I tried with and it worked fine

JS

jQuery(function($) {
    // NUM SWAP IN DIV
  setTimeout(function(){
   $("li.menu-item-33").replaceWith(
        "<li id='menu-item-33' class='numbertop menu-item menu-item-type-custom menu-item-object-custom menu-item-33'><a href='tel:8643004994'> Free Consultation (864) 300-4994</a></li>");
  },5000)
});

NOTE: I used setTimeout just to trigger the change

WORKING DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM