Is the CSS code example provided on the JSXGraph website functioning correctly?

I did my best to replicate this example from the JSXGraph website:

Below is the condensed HTML:

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">

  <title>Covid Sandbox</title>
  <meta name="description" content="Covid Sandbox">

</head>

<body>

  <script src="third party/jquery-3.5.1.min.js"></script>
  
  <script type="text/javascript" charset="UTF-8" src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="254f565d425744554d65140b140b15">[email protected]</a>/distrib/jsxgraphcore.js"></script>

  <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3a9b0bba4b1a2b3ab83f2edf2edf3">[email protected]</a>/distrib/jsxgraph.css" />

    <div id="jsxgbox">
    </div>
</body>
</html>

<style>
  .jsxgDefaultFont {
    font-family: Verdana, Geneva, Tahoma, sans-serif;
    font-size: 18;
  }

  .myFont {
      font-family: Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif;
      border: 1px solid black;
      padding: 5px;
      border-radius:5px;
  }
</style>  

<script src="js/test.js"></script>

By trying it out in test.js with some JavaScript code:

JXG.Options.text.cssClass = 'jsxgDefaultFont';

board = JXG.JSXGraph.initBoard('jsxgbox', {
    boundingbox: [-1,15,15,-1],
    showcopyright: false,
    axis: true,
    renderer: 'canvas',
    defaultAxes: {
        x: {
            strokeColor: 'grey',
            ticks: {
                visible: 'inherit',
            }
        },
        y: {
            strokeColor: 'grey',
            ticks: {
                visible: 'inherit',
            }
        },
    },
    zoom: {
        factorX: 1.25,
        factorY: 1.25,
        wheel: true,
        needshift: false,
        eps: 0.1
    },

    showZoom: false,
    showNavigation: false,
});

var txt = board.create('text', [0,0, " <span id='par'>(</span> Hello world <span id='par'>)</span>"], 
{
cssClass:'myFont', strokeColor:'red',
highlightCssClass: 'myFontHigh',
fontSize:20
});

board.update();

It seems like the inline HTML is not being correctly interpreted (displaying span\ Hello World \span). I'm uncertain about what I might be doing wrong.

Answer №1

It seems that the example provided in the wiki is outdated and the priorities of CSS classes, default CSS styles, and JSXGraph can be a bit tricky to navigate. For more up-to-date information, please refer to the API docs: . If you need to override the font-family settings, make sure to set cssDefaultStyle to an empty string:

JXG.Options.text.cssDefaultStyle = '';
JXG.Options.text.highlightCssDefaultStyle = '';

const board = JXG.JSXGraph.initBoard('jxgbox', {
    boundingbox: [-1,15,15,-1],
    showcopyright: false,
    axis: true,
    // ...
    });

var txt = board.create('text', [3,4, 
    " <span id='par'>(</span> Hello world <span id='par'>)</span>"
 ], {
    cssClass:'myFont',
    highlightCssClass: 'myFont',
    strokeColor: 'red',
    highlightStrokeColor: 'blue',
    fontSize:20
  });

To see it in action, visit https://jsfiddle.net/2jq8srpv/3/

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

Empty Media Viewer

I am encountering an issue with setting up a code, as it only displays a blank white page. Any suggestions on what might be causing this problem in the setup and assistance in resolving it would be greatly appreciated. <script type="text/javascript ...

Advantages and disadvantages of fetching image paths repeatedly from the database compared to retrieving them from session storage

Currently, I am displaying profile images using session like the following code snippet: <img src="<?php if (isset($_SESSION['userimage'])){ echo $_SESSION['userimage']; }?>" /> What are the advantages and disadvantages of ...

Using JavaScript to pass the href attribute value

On my HTML page, there are multiple links that reload the page when clicked. I want to capture the href value of each link the user clicks and store it in a variable called xhash: Here is the HTML: <a href='#taba' id='passid'>Li ...

What makes `Why await` stand out from all the other broken promises?

I am puzzled by the behavior of promises in Node.js and I have a question about it. Let's take a look at the following function as an example: async function proc(): Promise<void> { const resolve = new Promise((resolve) => setTimeout(resolv ...

What is the best way to send an object array from an express function to be displayed on the frontend?

//search.js file import axios from "axios"; export function storeInput(input, callback) { //input = document.getElementById("a").value; let result = []; console.log(input); if (!callback) return; axios.post("ht ...

Troubleshooting PHP's JSON array encoding issue

My current issue is with a PHP file that should be returning multiple records. Initially, everything was functioning properly. However, due to what I suspect is a minor error somewhere in the code, it has stopped working. When using Json_encode on my PHP ...

Obtain identical socket event in two separate useEffect hooks

I am facing an issue where I want to access the same event in two different useEffect functions on the same page. Despite my attempts, it doesn't seem to work as expected. Below is what I have tried so far. I'm wondering if it's possible to ...

Turning backbone's collection toJSON method into a collection object

One of the attributes of my model is a backbone collection. When I print out the model, everything appears to be fine, including the collection. However, when I use the toJSON() method on the collection and output it, the entire collection object is disp ...

Is there a method to prevent the json file from being constantly overwritten?

After running this code, I noticed that even when inputting a different userId, it still ends up overwriting the existing user instead of adding a new one as intended. const user = userId; const userObj = {[user]:valueX}; words.users = userObj; f ...

Manipulating child classes using jQuery

I am struggling to display an X icon next to a tab on my page when the tab is clicked, but I am facing difficulties in toggling its visibility. The issue arises when trying to access the span element within the tabs. $('.tabs .tab-links a').on(& ...

Enhance Your Website with Php Jquery Autocomplete Feature!

In the main page, there is an autocomplete input field along with an [ADD button]. When the user clicks on the add button, they are redirected to a page to add a new record. After saving the new record, the user is then redirected back to the main page. ...

Sign up for an observable only when a specific variable has been modified

I am facing an issue where I need to restrict the usage of rxjs's subscribe method to only certain property changes. I attempted to achieve this using distinctUntilChanged, but it seems like there is something missing in my implementation. The specif ...

I'm unable to modify the text within my child component - what's the reason behind this limitation?

I created a Single File Component to display something, here is the code <template> <el-link type="primary" @click="test()" >{{this.contentShow}}</el-link> </template> <script lang="ts"> imp ...

Formatting numbers in JavaScript objects

I am looking to iterate through an array of objects and convert the string values into numbers. Here is a sample scenario: I have data in a format similar to the variable provided below. When passing this array to a kendo chart, it seems to have trouble r ...

The SDK generated by AWS API Gateway does not include the JavaScript client file

After setting up my API with the AWS Api Gateway Service, I am now looking to integrate the javascript SDK into a basic webpage. The provided instructions for using the javascript SDK can be found here. However, they mention importing a js file named apig ...

What is the process for implementing save-exact in bunfig.toml file?

Do bun repositories have a setting similar to .npmrc's save-exact configuration? I attempted to include save-exact = true in bunfig.toml but it did not have any effect. My bun version is 1.0.0. ...

What is a way to simulate division using only multiplication and whole numbers?

The issue at hand: The stack-building API that I'm currently using in rapidweaver has limitations when it comes to division or floats, making it challenging to perform certain mathematical operations. Insights into the API's rules: This partic ...

Unlocking the secrets of the Fibonacci function through mathematical equations

Looking for a better way to calculate the fibonacci function using a mathematical formula. I've tried the following formula without success: fib(n) = ((1 + 5^0.5) / 2)^n - ((1 - 5^0.5) / 2)^n / 5^0.5 const fib=(n)=>{ return ((1+(5**0.5))/2)* ...

What is the best way to trigger a new jQuery .ajax call depending on the outcome of the first .ajax call?

My code includes a jQuery .ajax call: $j.ajax({ type: "POST", url: "/Services/Cart.asmx/UpdateQuantity", data: data, contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { var d = msg.d; ...

Reposition HTML content using regular expressions

My objective is to locate a block of HTML that contains comments and relocate it after the header section. The comment itself remains constant, but the content within the block varies across different pages and needs to be replaced using Dreamweaver' ...