Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8462065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:04:01+00:00 2026-06-10T14:04:01+00:00

I am having difficulties running an .each function to toggle a div on/off when

  • 0

I am having difficulties running an .each function to toggle a div on/off when a link outside of it is clicked. The function works, except I want it work for several different divs (right now, missiondiv and visiondiv). So I’ve created a variable prefix, which finds the id of a span and runs the function with this as the prefix. (Sorry if that doesn’t make sense). My script works only for the first span id. http://jsfiddle.net/jessica_b/KMJPf/

HTML for the link:

<div id="whoweare">
<span id="mission"><a href='#'>Mission</a></span></br>
<span id="vision"><a href='#'>Vision</a></span></br>
</div>

HTML for the div:

<div id="missiondiv" class="closed">Mission item</div>
<div id="visiondiv" class="closed">Vision item</div>

Javascript function:

    $.each($("#whoweare").find("span").attr("id"), function(){
    var prefix = $("#whoweare").find("span").attr("id");
    $('#' + prefix + ' a').click(function() {
        $('#' + prefix + 'div').toggleClass("closed");
        $('#' + prefix + 'div').toggleClass("item block");
        $(this).toggleClass('active-page');
        $container.isotope('reLayout');
    });
});

It runs within an Isotope, but all of that is working. The error resides in the above script and I’m not proficient enough in jQuery to be able to diagnose my mistakes yet! Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:04:03+00:00Added an answer on June 10, 2026 at 2:04 pm
    $('#whoweare span a').each(function(index, element) {
        $(element).click(function() {
            var prefix = $(this).parent('span').attr('id');
            $('#' + prefix + 'div').toggleClass("closed");
            // other actions
           return false;
        });
    });​
    

    http://jsfiddle.net/MtX7p/16/

    OR

    $('#whoweare span').each(function(index, element) {
        $(element).find('a').click(function() {
            var prefix = $(element).attr('id');
            $('#' + prefix + 'div').toggleClass("closed");
            // other actions
           return false;
        });
    });​
    

    http://jsfiddle.net/MtX7p/17/

    This is your full script: http://jsfiddle.net/KMJPf/49/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get a logging project up and running and having difficulties
I am having difficulties with my state machine. I use a function that returns
I am having difficulties getting a map / reduce operation to work. I'm a
I'm having difficulties seeing why one way works and way doesn't. I have; switch
hello friends i am working on a like module .and having some difficulties running
I am having difficulties getting the following to export. I am running CR2008SP2 and
I am having difficulties rendering several patterns (each with different texture) in the 2d
I'm having difficulties with an MFC application menu drop down. I want the drop
I am having some difficulties on trying this buddypress code to work: <?php $args
Guys I am having difficulties on retrieving struct member values after calling a function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.