Starting a div programmatically and then running into trouble when trying to close it, an error was encountered with an end tag for "div" without a corresponding start tag

I am looking to create the following HTML structure:

<div id="my-grid" class="isotope">
   <div class="myProject-item">....</div>
   <div class="myProject-item">....</div>
   <div class="myProject-item">....</div>
   <div class="myProject-item">....</div>
</div>

Essentially, every 4th row (out of more than 200 rows) with a class of myProject-item should be wrapped in

<div id="my-grid" class="isotope">

This is what I have tried:

@{
    var counter = 0;
    for (int i = 1; i < 200; i++)
    {
        counter++;
        if (counter % 4 == 0)
        {
          <text><div id="my-grid" class="isotope"></text>
        }
         <div class="myProject-item">....</div>
        if (counter % 4 == 0)
        {
           </div> // ***** on this line render breaks ******    
        }      
    }
}    

Parser Error Message: Encountered end tag "div" with no matching start tag. Are your start/end tags properly balanced?

Answer №1

It is important to mention that the closing tag </div> represents a content block.

        if (counter % 4 == 0)
        {
           <text></div> </text>
        } 

An alternative method is to use the @: sequence, which signals that the succeeding line of content should be considered as a content block.

@{
    var counter = 0;
    for (int i = 1; i < 200; i++)
    {
        counter++;
        if (counter % 4 == 0)
        {
          @:<div id="my-grid" class="isotope">
        }
         <div class="myProject-item">....</div>
        if (counter % 4 == 0)
        {
           @:</div> 
        }      
    }
} 

Answer №2

Make sure to move your initial <div> tag outside of the <text></text> in order for it to function correctly.

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

Removing consecutive pipe symbols in JavaScript

Looking for a way to remove excess pipe characters before a certain pattern in JavaScript. var testString="||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||f_test!!3!!||f_test!!4!!||f_test!!5!!||"; output ="||f_test!!3!!| ...

Creating two columns using React and Material-UI Grid while utilizing just one map function for iteration

I am facing a challenge with Material-UI Grid. I want to display the information from my map function in two columns instead of one. I tried adding another Grid item sm={6} and using the same map function, which resulted in two columns but with identical i ...

Using jQuery to send an Ajax request to the current page

I am trying to understand the functionality of jQuery Ajax when the URL is not specified. I want it to send data back to the same page where the Ajax request originates from. How can I access the 'GET' data once the Ajax request is completed? &l ...

Extracting values from PHP using AJAX

Whenever a user clicks on the download button, a zip file is successfully created on the server with the necessary files. However, instead of getting an alert with the location of the zip variable ($zip) from PHP as expected, it shows [object Object]. The ...

Vue: update data and trigger function upon completion of animation transformation, utilizing animation transformation completion listener

Check out this straightforward Vue example: https://codesandbox.io/s/sleepy-haze-cstnc2?file=/src/App.vue https://i.stack.imgur.com/zboCb.png Whenever I click on the square, it not only changes color but also expands to 200% of its original size with a 3 ...

The SELECT statement fails to fetch the most recent data from the database following an INSERT operation

When I make an AJAX request to the same page, my success function in PHP inserts a new record into a table called "some_table" in a MySQL database. Following that, I use jQuery to select data from this table and display it on the page. However, all old rec ...

Using jQuery to dynamically insert HTML content into a struts 2 web

In my Struts 2 webapp, I have successfully implemented the jQuery plugin for a form. However, I am facing an issue on certain pages where I reload divs based on user interactions using custom JavaScript functions like the one below: function doWhatever() ...

Arranging divs with CSS positioning

I struggle with positioning divs, especially in this particular situation. I am attempting to position boxes in the following layout: _ ___ _ |_|| ||_| _ | | |_||___| Is there a way to avoid manually defining pixel positions for each box and ins ...

Prevent user control postback from occurring when JavaScript is active

I have been on a mission to find a solution to this issue. Hopefully, someone in this community can shed some light on it! I developed a usercontrol that utilizes .NET web controls, but I want to enhance the user experience by avoiding full postbacks. As ...

Customizing skin CSS for DNN Portal and Page images

Currently, I have a unique custom skin that I personally created. It is implemented on multiple portals that I am responsible for managing. My goal is to incorporate the ability for the header image to change based on the specific page being viewed. The he ...

Add a <div> element to a webpage in a random location every time the page is refreshed

I have a variety of 2 types of <div>s displayed on a single page. Collection 1 consists of: <div class="feature">content 1</div> <div class="feature">content 2</div> ...and so forth. Collection 2 consists of: <div class ...

Prioritizing the validation of form controls takes precedence over redirecting to a different URL in Angular 2

Within an HTML page, there is a form with validation and an anchor tag as shown below: <form #loginForm="ngForm" (ngSubmit)="login()" novalidate> <div class="form-group"> <label for="email">Email</label> <i ...

Technique for adding an element's attribute to a span based on the element's class

I am aiming to display a maximum of three selections within my h4 tag, based on the number of options that the user clicks. For instance, the h4 tag should show 'Department1, Department 2,' if no elements are selected or have the class active, i ...

Using FUELPHP to make Ajax requests without relying on jQuery

After conducting thorough research, I have come to the conclusion that FUELPHP does not handle Ajax requests as efficiently and natively as some other frameworks like RubyOnRails. It seems that in order to perform Ajax requests with FUELPHP, one must manu ...

Two CSS Issues - One specific to mobile devices, the other unique to Chrome browser

Having trouble with the top banner not stretching all the way on iPhone. Any solutions? Here's a screenshot for reference: Below is the CSS applied to the div: #banner { background-color: #F7F7F7; background-size: cover; box-shadow: 0 0 ...

Tips for adjusting an image to fit your carousel

I am dealing with a carousel that has fixed dimensions (e.g., width=800px, height=450px), but the images I want to display in it have varying aspect ratios (16 : 9, 16:10, 1:1, etc.) and are larger than the carousel itself. I am attempting to resize all th ...

Choice pick, fails to display default

Default value is content1, but "text default show" is not displayed Please assist me.. jQuery(document).ready(function($) { jQuery('#select123').change(function() { jQuery('.co ...

Guide on utilizing VueJS plugins in the browser without any added layers

I have decided to incorporate VueJS into an old system instead of using JQuery. However, I am facing difficulties in utilizing plugins like I would with JQuery. For instance, when trying to import the "vuetable" library directly into my HTML using script t ...

Formatting tabular rows to appear as headers

I am currently developing a mobile website that is specifically designed for older phones with minimal CSS and HTML support. Due to these limitations, I have decided to utilize tables in my design. My goal on a certain page is to create a table row with a ...

Understanding the process of extracting map data from JSON files

I am currently working with Spring 3 and JQuery. My goal is to retrieve a Map containing element IDs and their values from my Spring Controller, and then use this data to update the View. Below is a snippet of the Controller code: @RequestMapping(value= ...