We help IT Professionals succeed at work.

Jquery if else not working ... WHY?

Mark Branscum
on
159 Views
Last Modified: 2017-04-11
got an error saying unexpected token else ...... am I missing a " ; " somewhere? or something?

<button id="btn">Click Me</button>

Open in new window

$(document).ready(function() {
  $("#btn").click(function() {

    If($("#btn").length > 0) {
      alert("Element Found");
    }
    else 
    {
      alert("Element not Found");
    }

  });
});

Open in new window

Comment
Watch Question

Lead Software Engineer
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
You must use small letter in if instead of If
Mark BranscumWeb Developer

Author

Commented:
lol seriously ..... Yep thats me old habits die hard .... I just couldnt see it for what ever reason .... thank you that was a fix
Mark BranscumWeb Developer

Author

Commented:
:) spot on my bad ,,, thanx for the fresh eyes
Shaun KlineLead Software Engineer
CERTIFIED EXPERT

Commented:
Glad to help.