views:

56

answers:

2

I have this HTML:

<div id='grid'>
<input type="button" value="edit"/>
<input type='button' value='update'/>
</div>

How to I attach a click event only to Update button. I know I could add a class to it or specity an id but both are not possible since it is in gridview.

I tried this:

$("input:button[@value='update']").click(function(){alert('test');}); 

but it displays an alert for both buttons. I know I must be doing something silly. Any help is much appreciated.

Thanks Kobi & Sarfraz for helping me out. Given below is the right answer.

$("input[value='update']").click(function(){alert('test');});
+4  A: 

Try this:

$("input[value='update']").click(function(){alert('test');});
Sarfraz
This is wrong - this is an `<input>`, not a `<button>`.
Kobi
It didn't work. Now it is not displaying an alert for both. http://jsfiddle.net/aX5wf/
Raja
@Raja: see my updated answer please.
Sarfraz
Thanks Kobi it worked :-) +1.
Raja
@Kobi: hmm didn't notice that, thanks anyways :)
Sarfraz
+2  A: 

As per the documentation for Selectors, in jQuery you should not have an @ when referring to attributes.

AakashM