Beginer
Beginer

Reputation: 240

Jquery correct way to find element

I have a button as follows:

 this._BtnCancel.ID = "btnCancel";
 this._BtnCancel.Text = "Cancel";
 this._BtnCancel.Click += new EventHandler(btnCancel_Click);

While populating a text box, I want to access this button and on its click do something as follows. What is the correct way to find the button?

 $("#" + txtBox).parent().parent().find('.btnCancel').click(function () {   $(".ui-menu-item").remove(); });

Upvotes: 0

Views: 42

Answers (2)

Jonathan Anctil
Jonathan Anctil

Reputation: 1037

You don't have to use find function, just use the right selector:

$("#btnCancel").click(function () { $(".ui-menu-item").remove(); });

Upvotes: 0

Chatra
Chatra

Reputation: 3129

If I am not wrong, Your button ID and button Class are same.

If you want to use ID

 $("#btnCancel").click(function () {
   //
  });

If you want to use Class

$(".btnCancel").click(function () {
  //
});

Upvotes: 1

Related Questions