Bind Event To Textbox


InterServer Web Hosting and VPS
Sony Playstation PS4 Pro Custom Build NVMe SSD Drive - Enclosure case and Crucial NVMe SSD
PS4 Pro Custom External SSD NVMe Drive

How I built a PS4 Pro Custom External SSD NVMe Drive...

NUC8i7BEH with memory
Intel NUC8I7BEH Review and Custom Build

This is my review of the Intel NUC8i7BEH and a summary of my build...

Card image cap
Asus M5A88-M EVO Review

This is my review of the Asus M5A88-M EVO motherboard...

Corsair Vengeance Blue 8GB (2x4GB) DDR3 PC3-12800C9 1600MHz Dual Channel Kit
Corsair Vengeance Blue Review

This is my review of the Corsair Vengeance Blue 8GB (2x4GB) DDR3 PC3-12800C9 1600MHz Dual Channel Kit memory...

Robotic Arm with USB PC Interface Review
Robotic Arm with USB PC Interface Review

This is my review of the Robotic Arm with USB PC Interface...

Bind Event To Textbox

What I show here is how in jQuery, to select all the textboxes in a certain area of the page such as in a div which has a class, and then assign a handler to an event for those elements. In the event I want to apply a jquery call to that particular textbox for which the event has fired.

So in this example I use jQuery to find elements which have a class name of 'classname', and then just to target the textboxes, (input[type=text]). With these elements I call .bind to bind a handler to the event 'click'. I create a handler which is passed a parameter called event, which can be used to target the actual textbox for which the event fired from. From that particular textbox I call removeClass, to remove the class called 'StyleTobeRemoved' which was attached to the textbox.


$('.className input[type=text]').bind("click", function(event) {
    $(event.target).removeClass("StyleTobeRemoved");
});


....


<div class="className">

    <input type="text" ...

</div>


Situations where this might be useful include validation, when the textbox gets focus you can change the style.

Sponsored Links
SolarSystem - AngularJS Demo
SolarSystem - Angular JS Demo

Check out my first Angular JS demo hosted in Azure, it helped win my first Angular contract. Put the sound on.