The <pre> element is not compatible with Bootstrap 4 modals

Attempting to integrate the <pre> tag within a bootstrap 4 modal has proven unsuccessful. The JSON content placed inside the <pre> tag is not displaying properly. Unsure of the missing element causing this issue:

Sample HTML code used:

<div class="modal" id="error_jobs_@guid" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="error_jobs_@guid">Error</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
      </div>
      <table class="table no-margin">
        <tbody>
          <tr>
            <td>
              <pre>@JsonConvert.SerializeObject(item)</pre>
            </td>
          </tr>
        </tbody>
      </table>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

Any insights on why this might be occurring, especially since it seemed to work fine with bootstrap 3? https://i.sstatic.net/A6Cj8.png

EDIT 1:

An executable example can be accessed here: here

Experimented with using the <code> tag which yielded slight improvement but still not ideal. Tried various combinations of <pre> and <code>, none producing the desired outcome. See image for how it appeared using the <code> tag:

https://i.sstatic.net/fu8Zw.png

Answer №1

The formatting is not displaying correctly because the "JSON object" is essentially a string without proper indentation in your HTML.

To fix this issue, you can convert the string to a JSON object and then back to a string with the correct indentation.

If you are retrieving the JSON from a database, simply parse it to a string and insert it into the HTML.

var jsonString = document.getElementById("pretty-json").innerHTML;
document.getElementById("pretty-json").innerHTML = JSON.stringify(JSON.parse(jsonString), null, 2);

You can view an example here.

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

The background image causes the scrollbar to vanish

As a beginner, I am in the process of creating a web page that features a consistent background image. However, I have encountered an issue where the scroll bar does not appear on a specific page called "family details" due to the background image. I atte ...

How to place an absolutely positioned div inside a scrollable div with overflow-y: scroll

Here is the HTML code: <div class="container"> <div class="scrollable-block"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, whe ...

What is the process for using JQuery to switch the class of an element to 'nested-class'?

Styling with CSS: #logo-container { position: fixed; right:5px; .home-page { /* homepage styling */ } .content-page { /* Modify the $element's class to this class */ margin-top: 78px; } } Using JQuery to change the class of #lo ...

Verify user credentials during login in a React application

My current challenge involves setting up a hardcoded authentication in React for user login using a form. Despite meeting the requirements for the "if" statement, it always returns the "else" statement. I am attempting to pass both the handleSubmit functi ...

Are there any methods for integrating a database file directly into an HTML file? If not, are there alternative approaches I could explore to achieve a similar result?

I have a school project where I need to create a website showcasing my work. I've created a database in Microsoft Access and I'm wondering if there's a way to integrate it into my website using html. The database is simple, just a table, a f ...

Limiting the scrolling capability within a flex container by using the nowrap

When using flex with nowrap, it appears that the horizontal scroll bar only allows moving to the right while the items on the left remain hidden. To demonstrate this issue, I have created a sample on CodePen: http://codepen.io/anon/pen/QpgvoZ This behavio ...

Executing Selenium test cases based on HTML tag is a key aspect of automated testing

I need to run my selenium test scenarios based on the value of an HTML tag, for example: <meta name="survey name" content="ABC Car"> The content represents different event types, with a total of 4 possible event types. ...

Exploring the animation potential of HTML5 canvas and Javascript through utilizing putImageData with animated gifs

I am interested in modifying the image data of each frame in an animated gif while it is playing in a web browser, using HTML5 canvas and Javascript. For instance, I would like to convert every frame to grayscale dynamically as the gif plays. Is this achie ...

How come the element is not appearing in the div even though it should be there?

The placement of the image and select menu within the same div element may be causing a display issue where only the first image is shown correctly and the select menu appears outside. Why does this occur? <body> <div style="height: 1080px; ...

It's a mystery unraveling the source of CSS margins and padding

Could someone please help me analyze this webpage? I am trying to make the center of the page white up to the navigation bar, at the bottom of the page, and horizontally up to the shadows on both sides. I'm not sure where this extra padding is coming ...

What is the best way to access all of the "a" elements contained within this specific div?

Chrome websites are built using the following structure: <div class="divClass"> <a class="aClass"></a> <a class="aClass"></a> <a class="aClass"></a> </div> Utili ...

width restriction to only accommodate on two lines

Whether my text is short or long, I always want to ensure that it remains within two lines by defining the width of my div. Short Text +-------------------------+ | Short text goes here | | Short text goes here | +---------------------- ...

Angular 10 carousel malfunction: unable to scroll images as intended

Recently, I attempted to integrate a bootstrap carousel into my angular web page. I copied the source code directly from the bootstrap site, so I assumed everything was configured correctly... Despite this, the carousel does not slide as expected. Additio ...

The checkbox is not properly aligned with the prompt due to the Bootstrap class

I am struggling with positioning a Bootstrap inline checkbox within the text prompt "Remember me on *this computer". The checkbox should appear right before the location marked by *. This issue arises from code borrowed from Chapter 9 of the Ruby on Rails ...

Why is my Javascript XMLHttpRequest onreadystatechanged event not triggering?

I am facing an issue with my html file and a .txt file stored in the same directory on a webserver. In the html file, I have the following code: <html> <head> <script> window.onload = function() { receiveMessage(); } function recei ...

Learn how to create a responsive flickr embedded video with Bootstrap!

I'm struggling to make the embedded video responsive. I attempted the solution mentioned in a Stack Overflow post but it didn't work for me. The video's width remains the same and doesn't scale down properly, appearing out of bounds on ...

Clicking on multiple external links will open them in separate tabs simultaneously

My attempts to find a solution on Google have been fruitless. I am in the process of creating a content aggregator, which is essentially a list of links to external websites. I want each link clicked to open in a new tab. Currently, I am using target="bl ...

Unable to switch between navigation items and icons

Currently, I am in the process of learning vanilla JavaScript and I'm trying to incorporate a navigation feature similar to when the hamburger icon is clicked. However, I have encountered an issue where I cannot toggle the hamburger icon to change it ...

What is the method to assign multiple values to ng-disabled in AngularJS?

Is there a way to assign multiple values for ng-disabled in AngularJS? The issue I'm facing is demonstrated in the following JS Fiddle: http://jsfiddle.net/FJf4v/10/ <div ng-app> <div ng-controller="myCnt"> <h3>A ->> ...

Storing HTML file input in an SQL database as a blob type: A Step-by-Step Guide

Currently, I am in the process of designing a website that includes forms for user submission. The input data provided by the users is stored in a SQL server database. While text, numbers, and dates are successfully being stored, I am encountering an issue ...