Search code examples
javascriptjquerybindliveautosuggest

jquery - why do i need live() in this situation?


I have a somewhat odd situation. I understand the premise of the live() and bind() functions, yet in a situation where i believe i dont need them, i seemingly do. I will explain.

I made an autosuggest in jquery. I included autosuggest.js at the top of my page. I then have an input field.

The basis of the JS works around:

$(".autosuggest").keyup(function()
{
}

This works - on keyup, my function executes etc as expected - i dont need to use live() or bind() as the input field is on the page from the get go...

Now.. I have also made a 'star rater' esque script. I have various

  • elements (which are styled), and on hover they are restyled...

     $('.rating li').mouseover(function() {
    }
    

    does NOT work, YET

     $('.rating li').live('mouseover',function() {
    }
    

    DOES.

    Why do i need to use 'live' in this situation, when i dont in the case of the autosuggest?

    Thanks


  • Solution

  • The only thing I can imagine that would cause this is a lack of a domready event. This should work:

    $(function () {
        $('.rating li').mouseover(function() {
        }
    });