开发者

This should be real easy. How to find a button through its Value (Jquery Selector)

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜