SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Aug 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Script Operating Backwards

    I'm trying to figure out why my script seems to be working in reverse. I have a page where there are hidden elements that will be shown when an image is clicked. The content should be hidden when the page is loaded, and only shown when the button is clicked. However, the page is loading with the content shown, and the images that are clicked actually hides the content,

    The page is http://scope-stage.scholastic.com/is...ive-Nonfiction and there are headings on the lower right hand side with images next to them (circles with "+" signs in them) One of those are "Complexity Factors", and the grey sub headings under it is what should be hidden.

    My jQuery script is:
    <script>
    $(document).ready(function()
    { $('div.hiddenComplexity').show();
    $('div.expandingBtn').click(function()
    { $(this).next('div.hidden').slideToggle('fast');
    return false; });
    });
    </script>
    where .hiddenComplexity is the div that has the content that should be hidden under "Complexity Factors", but it is showing instead, and hides when clicked (the opposite as intended). .expandingBtn is the name of the DIV that is clicked to show the hidden content. What am I doing wrong?

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,263
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by abtecas View Post
    However, the page is loading with the content shown ... The content should be hidden
    Quote Originally Posted by abtecas View Post
    $('div.hiddenComplexity').show();
    Perhaps try calling hide() instead of show().

    Also, make sure all the DIVs have the class you expect them to have ("hiddenComplexity", "hidden", etc).
    "First make it work. Then make it better."

  3. #3
    SitePoint Member
    Join Date
    Aug 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [QUOTE=Jeff Mott;5565477]Perhaps try calling hide() instead of show().

    Yes indeed. However, what about when I want them to be shown when the image is clicked?

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,263
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by abtecas View Post
    Yes indeed. However, what about when I want them to be shown when the image is clicked?
    The slideToggle() should already do that (assuming you've made sure that all the DIVs have the class you expect them to have ("hiddenComplexity", "hidden", etc)).
    "First make it work. Then make it better."

  5. #5
    SitePoint Member
    Join Date
    Aug 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    The slideToggle() should already do that (assuming you've made sure that all the DIVs have the class you expect them to have ("hiddenComplexity", "hidden", etc)).
    It does, but it's working backwards. The page loads with the div (.hiddenComplexity) shown, when it's supposed to be hidden, and hides when I click the image. It should be hidden on page load and then shown when I click. Eventually I'll have to have the expandBtn.png change to a circle with a minus sign on it, but that's another issue. Right now I just want to figure out why my script is working backwards

    Thanks for taking a look

  6. #6
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    13
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I see no div with the class "hiddenComplexity".

  7. #7
    SitePoint Member
    Join Date
    Aug 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by thetenfold View Post
    I see no div with the class "hiddenComplexity".
    Sorry, it's there now. Now the div hides as it should, however, the script will not toggle it.
    http://scope-stage.scholastic.com/is...ive-nonfiction


Tags for this Thread

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
  •