DM98
DM98

Reputation: 83

Javascript/jQuery working perfectly in Chrome but not in Firefox

I've been using some code recently that allows people to pay with Paypal Express Checkout when they are using our site in GBP currency, but I don't want the option there when they are using Euro's, Dollars, or any other currency.

In my Custom CSS I've used

.paypalbutton {display: none !important;}

Then in my Javascript/Jquery I've used

window.setInterval(function(){
if (jQuery(".currency-selector:contains('GBP')").length) {
    jQuery(".paypalbutton").attr('style', 'display: inline-block !important');
 } 1000});

The reason I've done it this way is because the Paypal button is loaded in dynamically with PHP. And for some reason .on and .live don't seem to work.

Now this works perfectly in Google Chrome, which is what I've been testing in. But for some reason this wont work in Firefox (haven't tested other browsers yet). So my question is, Why wont it work in Firefox?

Thanks for any help.

Some more info:

The code doesn't seem to be having any problems in firefox when typed into the console, its just that the paypal button that should be showing when on 'GBP' is not showing in firefox but does in chrome.

Chrome has:

.paypalbutton {display: inline-block !important}
<strike>.paypalbutton {display: none !important}</strike>

Firefox has:

.paypalbutton {display: none !important}
<strike>.paypalbutton {display: inline-block !important}</strike>

Upvotes: 1

Views: 217

Answers (1)

Sumon Sarker
Sumon Sarker

Reputation: 2795

You have an error defining setInterval function

Try like as below :

window.setInterval(function(){
  if(jQuery(".currency-selector:contains('GBP')").length){
    jQuery(".paypalbutton").attr('style', 'display: inline-block !important');
    /*jQuery(".paypalbutton").css({
       'display' : 'inline-block !important'
      });*/
 }
},1000);

Note : Console your output from both browsers. Check if there is any Script Error. Check if Javascript disabled/not supported by browser.

Here is the setInterval function syntax

window.setInterval(myCallbackFunction, DurationInMilliseconds);

Example :

var intervalID = window.setInterval(myCallback, 500);
function myCallback() {
  // Your code here
}

More details about setInterval() function. And jQuery Browser Support

Upvotes: 2

Related Questions