SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple document readys?

    Hello, I'm using a simple show-hide script on various IDs. The issue is as it stands right now each is a seperate JS that calls the document ready function via jQuery.

    Is there a way to combine this into one more flexible script or at least into one script in some form or another. Thank you so much for your time in advance!

    Below is an example:

    <script type="text/javascript">
    $(document).ready(function(){
    $("#loadDummy7").hover(
    function () {
    $("#dummy7").show();
    },
    function () {
    $("#dummy7").hide();
    }
    );


    });

    </script>
    <script type="text/javascript">
    $(document).ready(function(){
    $("#loadDummy8").hover(
    function () {
    $("#dummy8").show();
    },
    function () {
    $("#dummy8").hide();
    }
    );


    });

    </script>

  2. #2
    SitePoint Evangelist TommiChi's Avatar
    Join Date
    Oct 2008
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Place each hover event one after the other inside one document.ready function.

  3. #3
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    377
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As TommiChi said, it should work.
    Code JavaScript:
    <script type="text/javascript">
    $(document).ready(function(){
    $("#loadDummy7").hover(
    function () {
    $("#dummy7").show();
    }, 
    function () {
    $("#dummy7").hide();
    }
    );
    $("#loadDummy8").hover(
    function () {
    $("#dummy8").show();
    }, 
    function () {
    $("#dummy8").hide();
    }
    );
    });
    </script>

  4. #4
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, that works, I even based on your suggestion figured out a way to condense the script a bit! Much appreciated!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •