Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript $(div).ready(function(){ — Is this possible?

  • This topic is empty.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #37825
    jcoder
    Member

    Just wondering if this is possible to do?

    $(div).ready(function(){
    //code
    });
    #105425
    TheDoc
    Member

    Is there a particular reason why you are trying to do that?

    Would this not work:

    $(document).ready(function(){
    $("#your-div").....
    });
    #105437
    TheDoc
    Member

    I can’t seem to get it to work. http://jsfiddle.net/kra3r/

    I thought that’s exactly why we have this amazing plugin: https://github.com/desandro/imagesloaded

    #105482
    SgtLegend
    Member

    Using the .ready() method on the document would suggest all elements within the DOM are ready to be used so using the following is sufficient.

    $(function() {
    // jQuery code here...
    });
    #105520
    fwd
    Participant

    The philosophy of the ready() event in jQuery is based on the DomReady event of Vanilla Javascript, that is usually thrown by the window object. For other objects, like images, or divs, use the load() event.

    #105725
    jcoder
    Member

    Hi All,

    Why won’t the .load event work? But the Hover Does?

    This Code Works:

    $(document).ready(function() {
    $(".TH").hover(function() {
    $(this).attr("value", "##IVULP##"*1000);
    });
    });

    This Code Doesn’t Work:

    $(document).ready(function() {
    $(".TH").load(function() {
    $(this).attr("value", "##IVULP##"*1000);
    });
    });
    #105934
    devsign
    Member

    I agree with “SgtLegend” his suggestion is the best practice.

    #105935
    devsign
    Member

    I agree with “SgtLegend” using the $function method is good coding practice and one should definitely learn to do things the best way from the start.

    Is there a reason why you want to add a .ready to a div?

    #105964
    TheDoc
    Member

    @jcoder – load() isn’t going to do what you want it to.

    See my previous post about using the imagesLoaded plugin.

    #105985
    jcoder
    Member

    Thanks for all the Great Help Everyone!

Viewing 10 posts - 1 through 10 (of 10 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.