Forums

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

Home Forums JavaScript Advice on how to hide elements that don’t match, jQuery

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #33681
    Thadley
    Participant

    Html



    • Phase 1: Information

    • Phase 2: Planning

    • Phase 3: Design

    • Phase 4: Development

    • Phase 5: Finalizing

    • Phase 6: Maintenance


    This is the function I have right now in javascript


    function designProcess(){

    var index = $('#phases li');

    hideAll();

    $('#phases li').each(function(i){


    $(this).click(function(){

    alert('Phase position: ' + index.index(this) )

    if( i == index.index(this) ){
    $('#' + index.index(this)).show();

    }else{
    $('#' + index.index(this)).hide();
    }

    });//ends click function

    });//ends each function

    };//ends designProcess

    Goal: When I click phase 1, I want the appropriate div to be shown. When I click phase 2, it hides the current one and shows phase 2.

    Basically, When i click the given list item, the correct div gets revealed which is good. When I keep clicking the list items, the hidden divs keep showing but not hiding. I don’t see why the line of code inside the else statement doesn’t work.

    Can anyone help me figure out why lol? It would be much appreciated!

    #84106
    jamygolden
    Member
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.