0

Setting up a couple of things with OneSignal sdk. Basically, I want the site to show a certain piece of content only to people who have subscribed to my notifications. Copied a piece of code from their tutorial section. Everything works fine, if only one action is required. As soon, as I add another, i breaks.

Here is the piece of code

OneSignal.isPushNotificationsEnabled(function(isEnabled) {
    if (isEnabled)   
        document.getElementsByClassName('testsig')[0].style.display = 'block';
        //as soon as I add following line, it stops working
        document.getElementsByClassName('testhide')[0].style.display = 'none';
    else
        console.log("Push notifications are not enabled yet.");    
  });
Arlindo
  • 13
  • 5

1 Answers1

0

if condition contains multiple statements.So need to close {} it properly.Otherwise only one statement after the condition will be executed.

OneSignal.isPushNotificationsEnabled(function(isEnabled) {
    if (isEnabled)   {
        document.getElementsByClassName('testsig')[0].style.display = 'block';
        //as soon as I add following line, it stops working
        document.getElementsByClassName('testhide')[0].style.display = 'none';
          }
    else
        console.log("Push notifications are not enabled yet.");    
  });
Hikmat Sijapati
  • 6,869
  • 1
  • 9
  • 19