Why $(":select").focus does not work while $(":input").focus works?
Posted
by
user605660
on Stack Overflow
See other posts from Stack Overflow
or by user605660
Published on 2011-02-15T06:54:21Z
Indexed on
2011/02/15
7:25 UTC
Read the original article
Hit count: 93
Hi. I have a JQuery code which does something when input or select elements get focus. Although my code for input element works, select element does not work.
Here is what I do.
<body>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(":input").focus(function () { //this works
//do something
});
$(":select").focus(function () { //this doesn't
//do something
});
});
</script>
</body>
I tried some variation on select, such as using $("select") instead of $(":select"), but did not work either.
I am a beginner for JQuery.
I appreciate if you could tell me how I can make it work.
Thanks a lot!
© Stack Overflow or respective owner