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 8282659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:26:54+00:00 2026-06-08T10:26:54+00:00

Ok, I’m using Razor and jquery 1.5.1 if that affects the answer. I have

  • 0

Ok, I’m using Razor and jquery 1.5.1 if that affects the answer.

I have some simple jquery I copied from another post on this site. I have a variable number of sections that are rendered using the Razor engine.

I want to be able to hide / display the data under each section (which is wrapped in a div.)

so the HTML is

<div>Course 1<a class="toggle" href="javascript:void(0);">Click</a>
<div class="contentHidden" style="display:none;"> content here </div></div>
<div>Course 2<a class="toggle" href="javascript:void(0);">Click</a>
<div class="contentHidden" style="display:none;"> content here </div></div>

And the jquery is;

<script type="text/javascript">
$(document).ready(function(e) {
  $(".toggle").click(function (e) {
    e.preventDefault();
    $(this).children("div").toggle();
  });
});

The jquery is at the bottom of the view, and I have added in the document.ready bit to ensure that the <a> tags do exist.

One thing I have considered is that I am creating the page content using the razor @foreach(), however that must happen at the server before the content is streamed to the browser, so I don’t believe that I am doing this before the links are created, and shouldn’t need to use live or a delegate.

But I’m stuck now, so can anyone suggest how I can track this down (or better yet fix it 🙂

  • 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-08T10:26:56+00:00Added an answer on June 8, 2026 at 10:26 am

    The a elements don’t have a div child. Instead, it is the next element:

    $(this).next("div").toggle();
    

    Visually the div may be under the a element. However, what matters is the DOM structure, in which the div is a sibling of the a.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a

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.