Forums

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

Home Forums JavaScript Help please, problem with jquery accordion.. :/

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #35352
    SycoLV
    Member

    Hey guys and girls!
    I have a litle problem.. i made this litle javascript but there is a problem: http://jsfiddle.net/qvF6e/ They all open when clicked, but i need that only one opens per click and stay opened even if i open another.
    Can someone help me?
    Thanks!

    #91371
    Mottie
    Member

    Ok, I rewrote the script a bit… some things to note:

    * Removed links inside of the article to reveal more. Added code to add these.
    * Removed css to hide “.article_more”. This is important to keep the page readable in case the user has javascript disabled.
    * Added links using JS.
    * Changed links to toggle the view, then change the link text.

    Here is an updated demo, and the code:

    $(function() {

    $('.article_more').hide(); // hide using js in case user has js turned off

    // add more links
    $(".article").each(function() {
    $(this).append('More');
    });

    // toggle view
    $(".article").on("click", ".toggle", function() {
    var t = $(this);
    $(this).parent().find('.article_more').slideToggle(300, function(){
    t.html( $(this).is(':hidden') ? 'More' : 'Less' );
    });
    });

    });
    #91372
    SycoLV
    Member

    BIG BIG THANKS Mottie!

    #91374
    SycoLV
    Member

    Mottie i noticed that in ie7-9 the script dosent change more to less, so I cant toggle it back.

    Nevermind I found the error. I deleted the console.debug( t ); and it now works perfect in IE. Thanks agan.

    #91385
    Mottie
    Member

    Opps, forgot that I left that in! I took it out of the code :)

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