Reputation: 41
I have the following input type:
<input type="text" id="textid">
and I want to make it so if the user clicks it, or if it is currently clicked or selected, it will alert "clicked". I tried doing this, but it didn't work.
$('#textid').focus(function() {
alert('Function is clicked.');
});
What am I doing wrong?
Upvotes: 0
Views: 44
Reputation: 112
With that code, the alert form will be appeared consecutively. I think you should create a handle function before, then bind it when focusout
and unbind it when focus
. Demo
Upvotes: 1
Reputation: 206352
You're doing nothing wrong if:
you used:
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
and...
jQuery(function( $ ){ // (DOM is now ready and $ alias secured)
// ...placed your code here
});
Upvotes: 0