Unable to conceal with Bootstrap collapse

Having trouble collapsing the bootstrap

<a href="#demo" data-toggle="collapse">Expand/Collapse</a>

<div id="demo" class="collapse">
@item.Ans
</div

Answer №1

Without seeing all of the code, it's difficult to determine the exact issue, but one potential problem is using the same id (id="getAnsHint") for multiple elements. This violates HTML standards and could cause issues with any collapse functionality that relies on the id.

Answer №2

Enclose your PuzzleForHint. I haven't tested it yet, but if your HTML is generated like this <a href=someid123 >, it will cause issues.

@foreach (var item in Model){

<a href="'@("#PuzzleForHint"+i)'" id="getAnsHint"  class="btn"  data-toggle="collapse">Puzzle Hint</a>
<div id='"@("PuzzleForHint"+i)"' class="collapse'>
        <span style=" border: 1px solid;>@item.PuzzleForHint</span>
</div>

Also, could you please share the HTML code as how it is generated for each?

Answer №3

  1. A suggestion is to use ' ..' instead of " " in the line "@('#QuizForHint/getAnsHint'+i)"
  2. Check out data-target:https://www.w3schools.com/bootstrap4/tryit.asp?filename=trybs_collapsible&stacked=h
  3. Make sure to assign a unique id to each a
  4. Remember to close the style with ": style=" border: 1px solid;"

@foreach (var item in Model){
    <a href="@('#QuizForHint'+i)" id="@('getAnsHint'+i)" class="btn" data-toggle="collapse" data-target="@('QuizForHint'+i)">Quiz Hint</a>
        <div id="@('QuizForHint'+i)" class="collapse">
            <span style=" border: 1px solid;">@item.QuizForHint</span>
        </div>
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to adjust horizontal and vertical gutters in Bootstrap 5 and Hugo?

Utilizing Bootstrap 5 and Hugo for a website, I am trying to customize the column sizes in the test.md file. Specifically, I aim to have col-8 on the left column and col-4 on the right column by creating two shortcodes: row.html and column.html. To achiev ...

Using inline-block can be effective on certain occasions

Hi everyone, I'm currently facing a puzzling issue and not sure what's causing it. Sometimes the elements I've set as inline-blocks cooperate as expected, but then when I refresh the browser, they suddenly decide to misbehave. Below is my ...

Bootstrap dropdown malfunction

I am having trouble with my dropdown menu. The browser is cutting off the blue box in the dropdown area. I'm not sure if I need to add some CSS or make changes to the Bootstrap code to fix this issue. I haven't made any unusual modifications, jus ...

Swap the content of one div with another div using client-side code only

Currently, I am in the process of developing my personal website. To enhance user experience, I have implemented a vertical navigation bar on the left side of the page. My goal is to replace the content of a specific div with content from other HTML files ...

Get rid of the arrow that is displayed when using the `time` input type in HTML5

Recently, I encountered an issue with the default HTML5 code snippet. My custom background looked perfect except for a pesky black arrow appearing on the right side. In this image, you can see the problematic black arrow that needs to be removed. I attemp ...

Adjust link when scrolling through the webpage

I am looking to update the URL while scrolling instead of changing the menu class. Here's the reference I found: https://codepen.io/anon/pen/LdLgNo I made some modifications by adding push state, but I'm facing an issue with a fixed header. I ...

Content is positioned to the left in a horizontal layout without a set width

I am currently assisting a friend with the development of her website. While I consider myself somewhat of an amateur in web design, I usually manage to overcome challenges by dedicating hours to searching for solutions online. However, this time I have no ...

Using jQuery to establish a canvas element and define its dimensions by adjusting its width and height attributes

My attempt at using jQuery to create a canvas element was not quite as expected. Here is the code I tried: var newCanvas = $('<canvas/>',{'width':100,'height':200,'class':'radHuh'}); $(body).append(n ...

Achieving text alignment with icons in Angular

I'm having trouble aligning my text with the icon next to it despite trying to adjust margins. I would really appreciate any help or suggestions on how to resolve this issue. <div class="notification" [ngClass]="{'no ...

Is there a way to completely define CSS animation using only JavaScript?

I am looking to implement CSS animation on HTML elements that are generated entirely through a JavaScript function. The approach I am taking involves customizing settings and functions for each part of the animation, which is why this method is necessary. ...

I'm currently working with React and experiencing issues with my components being unrendered

I'm currently navigating a React tutorial and I'm having issues getting this code to display some buttons. I'm utilizing codepen.io to work on the code and can provide the tutorial link if needed. const clips = [ { keyCode: 81, key ...

How can I attach a cookie to a div that becomes visible after a few seconds of video playback?

After 20 seconds of video play, a div element appears. I am trying to set up a cookie so that once the div is shown, it continues to appear unless the user clears their cache (cookie logic). This is my current attempt - http://jsfiddle.net/9L29o365/ Any ...

How come the inclusion of a DOCTYPE tag impacts the styling of my CSS?

I am puzzled why the code below renders correctly without any issues until I add a doctype declaration: <body style="margin:0; padding:0; background-color:#eeeeee"></body> <div id="HeaderContainer" style="background-color:#eeeeee; color:Bl ...

What is the process of utilizing col-*-offset in decimal values using Bootstrap?

Can an offset be applied using decimals? For my situation, I require an offset of 3.5. I've tried using col-xs-offset-3.5, but it does not seem to work. ...

One limitation is that you cannot use JQuery to make multiple rows editable simultaneously

I have a unique challenge with implementing an edit button on each row of a dynamic Bootstrap table. I am attempting to toggle the button's icons and, depending on its current state, enable the corresponding row for editing. <td><button typ ...

iOS now supports hardware-accelerated CSS3 transitions for seamless and

I can't seem to get hardware acceleration working with my translate3d for top/bottom positioning. What could be causing the issue? .image { background:yellow; -webkit-perspective: 1000; -webkit-backface-visibility: hidden; ...

Refresh a webpage content dynamically without the need to reload the entire page

How can I implement YouTube's page navigation system that does not require the entire page to reload when switching pages? Do I need to incorporate Javascript or utilize an API for this functionality? ...

Unable to retrieve information from the table using watir-webdriver

As a beginner in Ruby and watir-webdriver, I am facing an issue with pulling data from a website. I am unable to access a specific cell in an HTML table as there are no distinguishing id, name, or class attributes. My suspicion is that the table is generat ...

Is it Possible to Load Images Without Using Javascript?

When I hover over certain links on my HTML pages, large images are displayed but take a while to load. I prefer not to use JavaScript to preload the images. Are there any alternative solutions available? ...

The modal is functioning perfectly with the initial row in the table

Is there anyone who can help me fix this issue? I've spent a lot of time trying different solutions, but none of them seem to work. I'm using a tailwindcss template for the modal and JavaScript to show or hide it. I'm having trouble findin ...