What could be causing the border-bottom for the span elements not to appear when generated programmatically?

I am looking to add a unique bottom border style to <span> elements with the class "indent". The border should be a specific size based on the level of indentation, and have color variations for alternating levels.

The current code I am using attempts to achieve this:

if (maximum_parenthesis_count > SPAGHETTI.maximum_underline_so_far)
{
    for(var outer = SPAGHETTI.maximum_underline_so_far; outer <= maximum_parenthesis_count; ++outer)
    {
        var identifier = '';
        for(var inner = 0; inner < outer; ++inner)
        {
            if (identifier)
            {
                identifier += ' span.indent';
            }
            else
            {
                identifier = 'span.indent';
            }
        }
        console.log('jQuery');
        console.log(identifier);
        console.log(outer + 'px solid black;');
        jQuery(identifier).css('border-bottom', outer + 'px solid black;');
    }
    SPAGHETTI.maximum_underline_so_far = maximum_parenthesis_count;
}

While the Chrome console logs indicate that the code is running correctly, the nested span elements do not display the desired bottom borders. It seems like there might be an issue with the jQuery.css() call. Although I can achieve the desired result with static stylesheets, the goal here is to generate dynamic borders based on the depth of indentation.

When inspecting the page in Chrome's dev tools, it recognizes the nested classes but does not show any corresponding CSS rules for the bottom borders. Even though the console logs show the code execution, it appears that the border styling is not being applied as intended.

How can I adjust the code so that each level of indentation has a distinct bottom border style, such as a 1px border for outer span.indent and a 2px border for inner span.indent in this example?

Answer №1

Here is a live demonstration: http://jsfiddle.net/hVbtz/7/

let size = 2;
let borderStyle = size +  'px solid red';
$("#box").css("border-top", borderStyle);

Remember, the semicolon is not necessary in the css method.

Answer №2

Give this a shot

if (maximum_parenthesis_count > PASTA.maximum_underline_so_far)
{
    for(var outer = PASTA.maximum_underline_so_far; outer <= maximum_parenthesis_count; ++outer)
    {
        var identifier = 'span.indent';
        console.log('jQuery');
        console.log(identifier);
        console.log(outer + 'px solid black');
        jQuery(identifier).css('border-bottom', outer + 'px solid black');
        // jQuery automatically matches all identifiers like span.indent
    }
    PASTA.maximum_underline_so_far = maximum_parenthesis_count;
}

Verify that your webpage contains span.indent element or otherwise.

To verify this, you can use the following code snippet

alert(jQuery('span.indent').length);

within the if statement

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

Pulling a div from beneath numerous other divs

I have been attempting to create a test case for a web application we are developing and I am on the verge of finding a solution, but there is one final hurdle that has me puzzled... Our requirement is to enable div elements to be draggable (which is work ...

I am able to apply the active class, but unfortunately, it does not get removed when the next click function is triggered

Good evening. I am currently attempting to modify a script that is designed to show/hide markers on a Google Map. The issue I am facing is the need to include an active class with each click event, which then needs to be removed when the next click event o ...

Performing modifications to a list on a JSP page received from a servlet

I am currently using the Rome API to read RSS feeds from a link and populate a list in a servlet. List<freshbean> allrss = new ArrayList<freshbean>(); RssDao rd = new RssDao(); allrss = rd.getAllRssFromUrl("http://feeds.feedburner.com/GeoBulle ...

Attempting to retrieve blog posts through an API call but receiving an error message indicating that the

In the blog application I developed, the home page is supposed to display blog posts from all authors with images of the posts and their profile pictures. However, I am encountering an issue where the images are not being displayed due to a (failed)net::ER ...

What is the best way to retrieve an image using AJAX and jQuery?

Is it possible to display an image using ajax jquery in a different way? $.ajax({ url: "c.jpeg", type :"get", dataType: "image/jpeg", success: function(data) { $("#myimg2").attr("src",data); } }) Here is the correspo ...

Unable to access 'read more' link in WordPress post - seeking solution

Is there a way to move the "read more" link to the end of the post on my blog homepage? Currently, all the content of the post is displayed on my homepage. I want to restrict the characters shown and have the link at the end. Thank you! ...

Finding Corresponding Values in an Array with JavaScript

I am working with an array of objects that have a specific format: [ { "card_details": { "cardType": "gift" }, "merchant_details": { "merchantName": "Walter Heisenberg1", "timeZone": "+05:30", } }, { "card_detai ...

Problem with displaying JSF Bootstrap Glyphicons

I recently encountered a problem in my web app where my Glyphicons in Bootstrap suddenly stopped working, appearing as empty squares for no apparent reason. Even after ensuring that the font files were intact and replacing them with fresh ones from versi ...

Guide to creating a function that assigns a value with the assignment operator in jQuery

Consider the function below: function ObjDataSet () { this.header = ""; this.dataIdx = 0; this.DataRows = []; this.CountRow = 0; } .... ObjDataSet.prototype.NameString = function(argIdx, argName, argValue) { var arrObj = this.DataRows[argIdx-1]; ...

Converting JSON to HTML without the use of external libraries

As a newcomer to JSON, I'm feeling quite puzzled by it. I need to transform a legitimate JSON string into a valid HTML string in order to display JSON on the web. jsonToHtml(“[{‘x’: 1, ‘b’: 2}, {‘x’: 100, ‘b’: 200}]") => “x:1x ...

Using jsdom as a package in a Meteor application is not possible

Recently, I came across an issue with my packages.json file. It looks like this: { "jsdom" : "0.8.0", "request" : "2.25.0" } As part of my project, I have the following code snippet: if (Meteor.isServer) { Meteor.startup(function () { var _ ...

Using Chartjs to Dynamically Update Data from Database Values

I'm encountering some difficulties while attempting to refresh my Chartjs doughnut chart with data retrieved from my database. Below is the ajax call that I've implemented successfully: $.ajax({ url: "<!--#include virtual="../include/e ...

Uploading JSON information retrieved from an API call into a MySQL database

Previously, I asked a similar question about passing JSON data to a dropdown menu using PHP. How can I arrange data array from an API request into an HTML SELECT OPTION LIST? Now, my goal is to insert the JSON data into a MySQL database. Here is my code ...

React Board not updating Cell Component

Edit After making changes to line 106 by adding setCellsSelected, I finally managed to trigger cell re-rendering. The functionality was baffling at first, React can be quite perplexing. Summary My current project involves visualizing depth-first search i ...

Tips for preventing parse errors caused by single quotes or apostrophes in the JSON response from PHP

Imagine having a PHP script that generates a json response like the example below: $ctype = ContentNego::desiredContentType(); header("Content-Type: $ctype"); if (ContentNego::flavor($ctype) == ContentFlavor::JSON) { echo '{ "name": "' . $ ...

Finding alternative solutions without using the find() method when working with Angular

How can I use an equivalent to find(".class") in AngularJS? I came across this solution: //find('.classname'), assumes you already have the starting elem to search from angular.element(elem.querySelector('.classname')) I attempted to ...

Adding a select option to a JQuery function: A step-by-step guide

I'm looking to enhance a jQuery function by adding both input and select form elements, but I'm unsure of the proper approach. Currently, I am only able to add one type of element - either an input or select form element. My goal is to update the ...

Efficiently updating child components using useRef and useEffect

Short version - how do I trigger a re-render of only one specific child component by monitoring ref? I have a table with rows. On hover, I want to show/hide a cell in the row but with a delay. The hidden content can only be revealed after hovering over t ...

Getting JSON data from an API using $.ajax

Currently, I am working on creating a random quote machine. To start off, I wrote the following HTML code to outline the necessary elements: <div id="quoteDisplay"> <h1 id="quote">Quote</h1> <h2 id="author">- Author</h2> ...

Is it possible to send fetch requests to dynamic endpoints, such as remote URLs that don't have CORS enabled? Can the http-proxy-middleware library handle using variables in endpoint targets?

Using the fetch('htp://list-of-servers') command, a list of URLs is retrieved: test1.example.com test3.example.com test5.example.com The next step involves executing a fetch() function on each of these URLs: fetch('test1.example.com' ...