views:

51

answers:

1

The following does not work on my page:

$("#bob").ready(function () {
    $("#bob").contents().find(".findme").css("background", "red");

    $(document.getElementById('bob').contentWindow.document).find('.findme').bind("mousedown", function() {
        alert(  $(this).text() );
    });
});

But if I add an Alert, which I assume adds some type of delay to let the iframe run before JS continues, it DOES WORK?

$("#bob").ready(function () {
    alert(1)
    $("#bob").contents().find(".findme").css("background", "red");

    $(document.getElementById('bob').contentWindow.document).find('.findme').bind("mousedown", function() {
        alert(  $(this).text() );
    });
});

Is the delay is what's making it work, shouldn't the ready be taking care of this? Also, is there a way to make the above LIVE, so the timing isn't an issue?

+2  A: 

Try putting that in a

$(document).ready(function() {

Instead of

$("#bob").ready(function () {

Iznogood