0

I'm a little bit confused. I am trying to add a change event to a text.

This is my html:

<input type="text" id="tag_search" placeholder="Start typing to search tags..." name="tag_search" size="33"/>

This is my script

$("#tag_search").change(function(){
    alert('Typing');
});

I'm aware that the change event will only fire once the input element loses focus but even when I do that the alert does not display.

but it will not work at all. Can anyone help me.

6
  • 6
    jsfiddle.net/a4b4oyvq -- Your problem isn't reproducible. Are you aware that the change event only fires when the element loses focus? Commented Nov 7, 2014 at 12:20
  • 1
    DOM is not ready probably. Try: $(function() { $('#tab_search').change(...); }) Commented Nov 7, 2014 at 12:21
  • change on text input fires when you leave the input. insted try with input Commented Nov 7, 2014 at 12:21
  • 1
    @George You forgot that jsFiddle runs any js on load by default while on your html page you have to specify it yourself :) Commented Nov 7, 2014 at 12:33
  • 1
    @nicael I didn't forget -- I wrongly assumed the OP would know :) Commented Nov 7, 2014 at 13:07

1 Answer 1

2

Your script should be

$(document).ready(function{
    $("#tag_search").change(function(){
        alert('Typing');
    });
})

It should be run on load.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.