If I have 2 textboxes, without using id's, how do I determine which textbox is firing off "keyup" events?
For various reasons I need to use classes instead of id's, where the class name is the same for both textboxes.
Infact, I could have the same textbox on the screen many times with the same class name.
The HTML looks something like this
<div class="outer_div">
<input type="text" class="mytextbox" />
<div class="inner_div"></div>
</div>
<div class="outer_div">
<input type="text" class="mytextbox" />
<div class="inner_div"></div>
</div>
<div class="outer_div">
<input type="text" class="mytextbox" />
<div class="inner_div"></div>
</div>
$('.mytextbox').keyup(function(event){
// play with event
// use $(this) to determine which element triggers this event
});
You can use the data- attribute to assign an id eg..
<input data-id="x" />
Then do something like.
console.log($(this).data('id'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With