DavidB
DavidB

Reputation: 2596

JQuery click of input button not firing

I've looked on the forum and my question is a duplicate of Button click event not firing in jQuery, except my code already matches the given answer.

I've stripped this down for you guys anyway, and can confirm that links with a class of disabled do not fire, so this proves the document ready and Jquery library are correct.

Javascript

$(document).ready(function () {
  // Prevents links from firing
  $('a.disabled').click(function (e) {
    e.preventDefault();
  });

  // Handles search
  $("#btnTreeSearch").click(function () {
    alert("click search fool!");
  });
});

Html

<input type="submit" value="btnTreeSearch" />

Any clues?

Upvotes: 0

Views: 115

Answers (2)

Adil
Adil

Reputation: 148110

You need to assign id to input to use id selector

Live Demo

Html

<input type="submit" id="btnTreeSearch" value="btnTreeSearch" />

Javascript

 $("#btnTreeSearch").click(function () {
     alert("click search!");
 });

Upvotes: 7

Ofir Farchy
Ofir Farchy

Reputation: 8037

Change value="btnTreeSearch" to id="btnTreeSearch".

Upvotes: 1

Related Questions