The customizing of font color with Fancytree's "extraClasses" feature is not being properly applied

In my web application, I have a tree that utilizes fancytree. Everything is functioning properly, except for the fact that I need to set the font color to red for certain nodes. I have implemented the use of extraClasses in my JSON, which is successfully applying to the correct nodes as confirmed through the browser's debugger.

While I am able to easily apply CSS attributes such as font-style and background-color, for some reason the font color is not being applied to the base span.fancytree-title. Instead, all nodes are appearing in black.

CSS:

span.OrgDataTreeNotChecked
{
    background-color: #EFFAFA;
    color: red !important;
    font-style: italic;
}

The C# code generating the relevant extraClasses:

if (org.Status == "NotChecked")
    item.extraClasses = "OrgDataTreeNotChecked";

Upon inspection in the browser debugger, the color attribute is clearly present:

Yet, when I inspect the span.fancytree-title, the color is being overridden and displayed in black instead.

Various attempts have been made to solve the issue, such as trying to override the color for those nodes in jQuery within the .init event of the Fancy tree and within the document ready function:

$(".OrgDataTreeNotChecked").closest(".fancytree-title").css({ "color": "red" });

Even the brute force method of setting the color for all .fancytree-title elements was attempted:

$(".fancytree-title").css({ "color": "red" });

However, these attempts proved to be ineffective. I am at a loss for solutions. The font color simply refuses to apply, while all other attributes function correctly. Assistance is greatly appreciated!

Answer №1

After numerous attempts and experimenting with Chrome's "Inspect element" feature, I finally discovered a solution that worked for me:

span.OrgDataTreeNotChecked > span.fancytree-title {
    background-color: #EFFAFA;
    color: red!important;
    font-style: italic;
}

It appears that the additional class specified in the extraClasses parameter is applied to a fancytree-node span that encloses a fancytree-title span, so using the right angle bracket operator was the key to success.

Answer №2

After much effort, I finally managed to crack it. It may not be the most flawless solution, but it gets the job done.

The nodes don't show up in the DOM until each parent node is expanded, so the collection within $(".OrgDataTreeNotChecked") is actually empty during the tree's init event and the document's ready function.

However, the tree does have an expand event that triggers as each node is expanded. This event initially populates the DOM with the child nodes. To handle this, I had to add the following event handler to the tree:

expand: function(data) {
    $(".OrgDataTreeNotChecked").children(".fancytree-title").css({ 'color': 'red' });
},
...

This code then turns everything red. The reason why I consider it not ideal is because the text briefly appears black on each load before turning red as intended.

It will suffice for now, but if there are any better suggestions out there, please share :)

Answer №3

To customize the style of your tree node in CSS, you can use the following code snippet:

span.fancytree-node.OrgDataTreeNotChecked > span.fancytree-title,
span.fancytree-node.OrgDataTreeNotChecked > span.fancytree-title:hover {
    color: red;
}

Make sure to add your custom class to the li element like this:

<li class="folder expanded">Override CSS style per node
    <ul>
        <li class="OrgDataTreeNotChecked">item</li>
        <li class="folder OrgDataTreeNotChecked">item</li>
    </ul>

You can see a working example of this implementation here:

Answer №4

Perhaps attempting a different approach may resolve the issue at hand.

span.fancytree-title.OrgDataTreeNotChecked
{
background-color: #EFFAFA;
color:red !important;
font-style: italic;
}

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

When inline elements are positioned right next to block elements

Can inline and block elements be placed on the same level without wrapping in HTML? Does it matter if they are wrapped or not? For example: <div class="name"> <span class="name__text">List name</span> </div> <div class="li ...

Display endless data within a set window size

I am looking to create a fixed-size window for displaying text from the component <Message/>. If the text is longer, I want it to be scrollable within the fixed window size. See screenshot below: Screenshot export default function AllMessages(){ ...

Tips for aligning a Bootstrap row in the center

I need some help centering this temperature converter on the page. I've tried adjusting the columns and rows, but the alignment is still off. Here is a screenshot for reference: https://i.sstatic.net/xR8rA.png Below is the code I am using: < ...

Issue with Jquery Ajax

Hey there, I've run into a bit of a snag and am in need of some guidance. My current issue involves trying to parse an XML file by utilizing JQuery's .ajax function. Below is the code snippet in question: The code above is saved in a test.js fil ...

Making a JavaScript script compatible with select drop down menus that can handle multiple selections

After searching through various sources, I came across two threads that address my question regarding the code to use. Despite finding solutions, I am struggling to understand how to implement the script. My limited experience with JavaScript is likely cau ...

Uploading and previewing multiple images on a canvas

After successfully creating single upload for images and placing them on canvas as seen in http://jsfiddle.net/StJnY/, I am now looking to adapt the script for multiple image uploads. Here is how I plan to modify the script: JS : $(function () { $(&a ...

A jQuery component with built-in event triggers

Here's an example that illustrates the concept: a widget needs to utilize its own method as a callback: $.widget("custom.mywidget", { _create: function() { this.invoke("mymodule", "myaction", {arg: this.options.value}, this.parseData); ...

Missing CSS in dynamically loaded content on IE

I have been searching everywhere, but I just can't seem to find a satisfactory answer to this particular question. Whenever I load a few items on the page, they are displayed correctly at first. However, if a user decides to change the language, the ...

The functionality of cloning an object is experiencing issues on a webpage containing jQuery code generated by a PHP script

<li style="padding: 5px; width: 150px; overflow: hidden; float: left; height: 202px;"> <div class="title"> <a href="/index.php?option=com_virtuemart&amp;view=productdetails&amp;virtuemart_product_id=68&amp;virtuemart_category ...

Styling the navigation bar using CSS and positioning a <div> element underneath

Struggling to design a navbar using Bootstrap and have a div positioned underneath it that fills the remainder of the page? You're not alone! As someone new to Bootstrap and CSS, this can be tricky. Here's an example of how I created a navbar: ...

What is the reason the text does not have a border around it?

The border is supposed to be around the text, but it isn't showing up. Where did I go wrong? Could it be that I need to set a position? html { width: 100%; height: 100%; margin: 0; padding: 0; } body { width: 100%; height: 100%; marg ...

Is there a way to modify Bootstrap tabs when they are hovered over?

This may seem like a simple question, but I've been struggling to figure it out. I'm attempting to have the bootstrap tabs switch when the mouse hovers over them. <div class="container"> <nav class="nav nav-tabs" ...

What is the reason for the consistency in the effects of vertical align: text bottom and vertical align: bottom?

The baseline positioning of a line box is impacted by all elements within that line. .short-box { width: 30px; height: 30px; background-color: pink; display: inline-block; } .box { background-color: ...

Retrieve the input value closest to the selected row

I need to extract the price and currency value of a checked row containing a checkbox. The price is specified in a text box while the currency is selected from a dropdown menu. $(document).ready(function() { $('#test').click(function(){ ...

Issue encountered with the triggerWord <input> and JavaScript

I am struggling to get the page http://example.com to load when I type trigger in the <input> text box. It was working at some point after a few modifications, but now it doesn't seem to be functioning properly. Can anyone help me figure out wh ...

Retrieving a variable value from an AJAX call for external use

Looking for a solution to pass the generated JSON response from an ASMX web service accessed via AJAX to an outside variable in another function. Below is the code snippet for reference: function setJsonSer() { var strWsUrl = &apo ...

What is the solution for fixing scrolling while keeping the header fixed and ensuring that the widths of headers and cells are equal?

Is there a way to set a minimum width for headers in a table and provide a scroll option if the total width exceeds 100% of the table width? Additionally, how can we ensure that the width of the header and td elements are equal? Below is the HTML code: ht ...

Acquire Table Element Using Javascript

I have a HTML table that contains information such as names, addresses, and phone numbers. Within each row of the table, there is a link that can be clicked to open a popover. When a popover is opened, I want to save the name from that particular row. The ...

The $_POST variable is not filled with the information displayed in the payload

When submitting a form with AJAX, I am able to view the payload data using the developer tools in Chrome: ------WebKitFormBoundaryiwCAdpY9aJH3D9h9 Content-Disposition: form-data; name="datafixId" 666 ------WebKitFormBoundaryiwCAdpY9aJH3D9h9 Content-Dispo ...

Is it a jQuery photo gallery that showcases images sourced directly from a database?

I'm feeling a bit stuck with my coding and could really use some assistance. I am currently working on implementing a jquery gallery plugin that pulls images from a database using a PHP script instead of directly from a folder on the server. <?php ...