jessnoonyes Posted March 18, 2013 Share Posted March 18, 2013 Hi guys! I'm having an issue with a bit of javascript. I have multiple divs on a page, with a portion of their content hidden. In theory you should be able to click one of two links to toggle the div (the div comes with two toggle links). What I have below works, but you have to click one of the links twice before it will trigger and I"m not sure why: $(function(){ $(".toggle-content").slideUp(); $(".toggle" ).toggle( function() { $(this).parents(".article").children('.toggle-content').slideUp('slow'); $(this).parents(".article").children('h6').removeClass("arrow-down"); $(this).fadeIn("fast"); }, function() { $(this).parents(".article").children('.toggle-content').slideDown('slow'); $(this).parents(".article").children('h6').addClass("arrow-down"); $(this).fadeOut("fast"); } ); $("h6" ).toggle( function() { $(this).parents(".article").children('.toggle-content').slideUp('slow'); $(this).removeClass("arrow-down"); $(this).parent(".article").find(".toggle").fadeIn("fast"); }, function() { $(this).parents(".article").children('.toggle-content').slideDown('slow'); $(this).addClass("arrow-down"); $(this).parent(".article").find(".toggle").fadeOut("fast"); } ); }); When I change the line from toggle to click, it works without issue. Like $("h6").click(funciton() { But unfortunately when that happens it won't toggle closed again. I'm sure it's something really basic and silly - I'm just not that great with javascript. Any input would be greatly appreciated! Thank you. Link to comment https://forums.phpfreaks.com/topic/275831-have-to-click-twice-to-toggle-the-div/ Share on other sites More sharing options...
gergy008 Posted March 18, 2013 Share Posted March 18, 2013 Uhm... this is the PHP help... not the Javascript help. Only a handful of the guys here specialise in jQuery. Link to comment https://forums.phpfreaks.com/topic/275831-have-to-click-twice-to-toggle-the-div/#findComment-1419436 Share on other sites More sharing options...
Psycho Posted March 18, 2013 Share Posted March 18, 2013 ** Moving to JS Forum ** Link to comment https://forums.phpfreaks.com/topic/275831-have-to-click-twice-to-toggle-the-div/#findComment-1419440 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.