1

Desperate late night coding before a submission.

I have two HTML objects with two separate class names that I'm looking to bind the same event with different actionlisteners.

<form class="form-wrapper cf" action ="">
  <input id="searchInput" type="text" placeholder="Search for Sets or Cards" required>
  <button class="searchButton" type="button">Search</button>
</form>

I've managed to handle the button on click, and after reading the documentation for "on" I see that you can bind multiple listeners to the same class. However I can't figure out if it's possible to do the keyup as well.

$(".searchButton").on("click" ,function(){
snowp
  • 495
  • 1
  • 6
  • 22
user1870954
  • 207
  • 3
  • 14

4 Answers4

7

Try this:

$('.searchButton, #searchInput').on('click keyup' ,function(){
dersvenhesse
  • 6,276
  • 2
  • 32
  • 53
  • That did the charm, thanks. Was a lot easier than I expected. I was only going to make it hit the server on return keyup, but this is much sexier as well. Many hearts – user1870954 May 07 '13 at 09:23
2

Are you looking for something like this: jsfiddle link http://jsfiddle.net/XAGD9/2/

$(document).on("click keyup",".searchButton" ,function(){
V31
  • 7,626
  • 3
  • 26
  • 44
1

You can do this:

$(".form-wrapper").on("click keyup", ".searchButton",function(){
    // Your code here
});
palaѕн
  • 72,112
  • 17
  • 116
  • 136
-1

try this :

     $(".searchButton").bind("click keyup" ,function(){});
Ahmed Alnahas
  • 263
  • 1
  • 4