views:

75

answers:

2

Hi, I'm having a problem getting content loaded into a document to fire jQuery scripts.

I have the following code

$(".jquery-selectbox").change(function(e) {
                url = this.options[this.selectedIndex].value;
                $('#pane2').fadeOut(500, function () {
                    $('#pane2').fadeIn(500);
                    $("#pane2").load(url, '', reinitialiseScrollPane2);
                });
});

that should cause a drop box to load a link based on the value selected. The drop down box is loaded into the page on document ready via jQuery's .load. It has a class of '.jquery-selectbox'

I tried to follow the jQuery documentation on .live based on 'change' but it wouldn't work for me, even after updating to 1.4.2. What should I do to make this work?

Thanks!

+2  A: 

Try this -

$(".jquery-selectbox").live('change',function(e) {
                var url = $(this).val();
                $('#pane2').fadeOut(500, function () {
                    $('#pane2').fadeIn(500);
                    $("#pane2").load(url, '', reinitialiseScrollPane2);
                });
});
Alpesh
This is what I was trying (based on the jQuery documentation). I guess I should have explained it better in my description. This method doesn't seem to work for me. Any ideas why?
Thom
A: 

YOur script works, look here:

http://jsfiddle.net/dactivo/Q93VR/

netadictos
I think he's trying to say that the `.jquery-selectbox` element doesn't exist on page load.
Matt Huggins
yeah, my script works fine on its own. The problem is when the element it refers to is loaded into the page after the initial page load.
Thom
In that case Alpesh answer should work, (with "live").
netadictos