views:

3481

answers:

5

The code below works as expected in FF but not in IEs...

$(document).ready(function() {

    $('div.facet_dropdown select').live('change', function() {
        var changed_facet = $(this).attr('id');
        var facets = $('select', $(this).closest('form'));
        var args = window.location.href.split('?')[0] + '?ajax=1';
        var clear = false;
        for(var i = 0; i < facets.length; i++) {
            var ob = $(facets[i]);
            var val = ob.val();
            if(clear) {
                val = '';
            }
            args += '&' + ob.attr('id') + '=' + val;
            if(ob.attr('id') == changed_facet) {
                clear = true;
            }
        }

        $.getJSON(args, function(json) {
            for(widget_id in json) {
                var sel = '#field-' + widget_id + ' div.widget';
                $(sel).html(json[widget_id]);
            }
        });

    });

});
+11  A: 

$.live() does not support the change event:

Currently not supported: blur, focus, mouseenter, mouseleave, change, submit http://docs.jquery.com/Events/live

Try using livequery instead?

cpharmston
Perfect! Thanks so much! livequery does the trick!
fabian
Ran into this exact problem and even read the docs and missed the non-supporting-ness.
wesgarrison
Just wanted to post an update to this. First, I noticed the URL you posted is now redirecting to http://api.jquery.com/live/ . Second, the passage you quoted regarding change event being "currently not supported" is no longer found on this page, as it seems like I.E. support now works in jquery 1.4.2. I had just come across this same problem on a page using 1.3.2, upgraded it to 1.4.2, and it's now working like a charm. Thanks!
Funka
+1  A: 

Here is answer with greater detail .

Roger
+2  A: 

Note: jQuery 1.4 now supports the live function for all normal events. It didn't work with IE8 until recently, but I believe this is fixed with jQuery 1.4.2. See this resolved jQuery ticket: IE8 DOES NOT SUPPORT THE CHANGE EVENT WHILE USING LIVE

Gabe Hollombe
A: 

I used -`jQuery('#id').find('select').live("click", function(){

    $(this).change(function(){

                  //your code

             });
});`
A: 

Use delegate() function instead live(). It the same as live, but supports more events and works fine in IE. In yout case it will be

$('div.facet_dropdown select').delegate('change', function() { ... });

and correspondent undelegate() function

Madman