Loading ...

How to bind events to controls except one control with jQuery | CodeAsp.Net

How to bind events to controls except one control with jQuery

 /5
0 (0votes)

 

In this blog I will explain how to bind events to controls except one control with jQuery .In some requirements we have to bind a event suppose keydown to all textboxes except a particular textbox and on that particular textbox we want to have different functionality on keydown event. Below is the code snippet for it:

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

 

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

 

</head>

<body>

<div id="testdiv">

<input id="Text1" type="text" /><br />

<input id="Text2" type="text" /><br />

<input id="Text3" type="text" /><br />

<input id="Text4" type="text" /><br />

<input id="Text5" type="text" /><br />

<input id="Text6" type="text" /><br />

<input id="MyOtherInput" type="text" />

</div>

</body>

 

<script type="text/javascript">

 

$(function()

{

$('input[type=text]').not('input[type=text]#MyOtherInput').bind('keydown', function(e)

{

alert('Common for all ');

});

 

$('input[type=text]#MyOtherInput').bind('keydown', function(e)

{

alert('Only for MyOtherInput');

});

 

});

 

</script>

 

</html>

 

 

So above we discussed how to have common functionality to all the textboxes except one which is bind with different functionality.
Do let me know your feedback, comments.

Comments (no comments yet)

Top Posts