If-else -help wanted

If-else -help wanted
0

#1

Hi,

Could someone help me please… Why the first event handler does not work and second works ok. I am really confused here :confused:

$(function(){
  $('.btn').click(function() {
    If ($('body').hasClass('open')) {
      $('body').removeClass('open');
    } else {
    $('body').addClass('open');
    }
  })
})


$(function(){
  $('.btn').click(function(){
    $('body').hasClass('open') ? $('body').removeClass('open'):$('body').addClass('open')
  })
})

#2

Capitalized If, should be if.

Also, formatting your code makes it easier to spot errors on the forum. I did it for you this time, but you can do it yourself like this:


#3

If should be lowercase.


#4

Thanks you @JacksonBates and @kevcomedia you quick answers. I will try to do the modifications next time posting code to forum :slight_smile: I got the code working and my random quote machine is almost ready now :smile_cat:

-Zumi-