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');});
Try this:
$("input[value='update']").click(function(){alert('test');});
As per the documentation for Selectors, in jQuery you should not have an @
when referring to attributes.
jQuery uses CSS selectors, and to select that, you should not use @
in CSS.
精彩评论