What is the best way to compile an array of permissible values for a specific CSS property?

One interesting aspect of the CSS cursor property is its array of allowed values, ranging from url to grabbing.

My goal is to compile all these values (excluding url) into an array in JavaScript.

The real question is: how do I achieve this without hardcoding it? What if new values are added or old ones are removed?

Fetching this information from a documentation site like MDN seems excessive. Is there a more efficient way provided by the language itself?

Answer №1

Regrettably, the only option available is to manually code it or utilize web scraping techniques. JavaScript lacks an inherent function for this specific task.

It's worth noting that certain properties such as height, width, etc. can accommodate various values.

Answer №2

If you're unsure whether you're using PHP, here's a method to extract information from a webpage containing CSS properties. It's important to obtain permission from the site in order to avoid overloading their server with repeated accesses to property pages. The code below is limited to displaying only 10 results. While utilizing the "ob" functions may not be the most elegant solution, it gets the job done.

<?php
ini_set('max_execution_time', 600);
ob_end_clean();
ob_implicit_flush(true);
libxml_use_internal_errors(true);

function getValuesForElement($element) {
    $valueArray = [];
    try {
        $dom = new DOMDocument();
        $dom->preserveWhiteSpace = false;
        $dom->loadHTMLFile('http://css-infos.net/property/' . $element);
        $data = $dom->getElementsByTagName('code');
        foreach($data as $css) {
            $val = preg_replace("/\s+/S", "", $css->nodeValue);
            if(!empty($val)) {
                $valueArray[] = $val;
            }
        }
    } catch(Exception $e) {

        // Log error..

    }

    return $valueArray;
}

function getElements() {


    try {
        $i = 0;
        $elementsArr = [];
        $dom = new DOMDocument();
        $dom->preserveWhiteSpace = false;
        $dom->loadHTMLFile('http://css-infos.net/');
        $data = $dom->getElementsByTagName('li');
        foreach($data as $css) {
            if($i === 10) {
                break;
            }
            $nodeVal = $css->nodeValue;
            if($nodeVal == "Webkit CSS properties") {
                continue;
            }
            $elementsArr[$nodeVal] = getValuesForElement($nodeVal);
            echo "getting <strong><em>".$nodeVal."</em></strong> values..\n";
            $i++;
            sleep(1);
        }
    } catch(Exception $e) {

        // Log error..

    }

    print_r($elementsArr);
}

echo "<pre>";
getElements();
die();
?>

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

Hide an Angular button when a page is loaded, depending on the information found in a table

How can I hide the Submit button in a table row if a certain condition is met based on information from the database? I attempted to create a function that returns true or false, but it ends up crashing my program because it runs continuously. I also trie ...

Utilizing i18next-express-middleware for seamless language switching based on user input

As a newcomer to node.js, I am looking to internationalize my application. To kickstart this process, I have utilized the template available on i18next-express-middleware github in conjunction with resources from the i18next website. My goal is to enable u ...

Is the code generated by Webflow.com functional and practical?

Recently, I have discovered the wonders of www.webflow.com for creating an admin layout. It excels in generating a flexbox layout based on my PSD design without requiring me to manually code with Gulp. My plan is to further simplify the process by breaki ...

Tips for utilizing the Apollo cache consistently during page transitions in NextJs

In the official examples repository of NextJS, I found this apolloClient.js file: import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client' import { concatPagination } from '@apollo/client/utilities' import merge from &apos ...

Codeceptjs does not have the capability to scroll or swipe down without being linked to a specific element

I'm facing an issue with scrolling/swiping down in an Android application while using codeceptjs. The method I'm currently using only works on the visible element, but I need to scroll down to the bottom of the page or a specific element without ...

Converting a JavaScript object into JSON format

I am currently working on serializing a JavaScript object to JSON. Here is the code I have written so far: var info = {}; ... $.each(data, function (key, value) { info["name"] = value.name; info["id"] = value.id; ...

How to display information from a JSON file using dynamic routing in a React.js application

I'm currently working on a project to replicate Netflix using reactjs, but I've hit a roadblock and can't figure out what to do next. I've tried watching YouTube tutorials and reading articles online, but I haven't been able to fin ...

Ways to customize the default countdown timer

I came across this amazing project at https://codepen.io/mattlitzinger/pen/ysowF. While the project is wonderful, I am looking to make some modifications to the code, specifically targeting a specific date. Here is the JavaScript code snippet: var tar ...

Each time the page is reloaded, an error message pops up: "TypeError: Cannot access attributes of an undefined object (referencing 'name')."

Everything seems to be working fine in my app, except for one issue when I try to refresh the page where an event is being edited (EditEvent Component). The error message I receive is: Uncaught TypeError: Cannot read properties of undefined (reading ' ...

Tips for creating a clickable title that directs to a URL

I am currently using the "Import All" WordPress plugin to bring in an Excel file containing numerous hyperlinks that point to specific Custom Post Types and a designated field. These hyperlinks are separated by commas from the corresponding title. For exam ...

Tips for accessing the URL in PhoneGap and parsing the response with jQuery

Currently, I am working on a task in PhoneGap which involves creating a registration page. When the user clicks on the registration page, the values entered will be sent to a specific URL. If the user is already registered or not, the data will be returned ...

What is the best way to disable the button hover effect after it has been clicked?

Many posts I've come across have similar issues to mine, but the suggested solutions are not working for me. I am struggling to remove the hover property of my button when it is clicked before triggering the removal event I have set up. Edit: Just t ...

An unfamiliar data type is provided as a number but is treated as a string that behaves like a number

Here is the code snippet in question: let myVar = unknown; myVar = 5; console.log((myVar as string) + 5); Upon running this code, it surprisingly outputs 10 instead of what I expected to be 55. Can someone help me understand why? ...

Endless Scroll Feature in Javascript

A brief tale: I am in search of a way to extract data from a website that features infinite scroll without actually implementing the infinite scroll feature myself. My plan is to create a script that will auto-scroll the page from the browser console, wai ...

Issues arise when attempting to retrieve information in NextJS from a local API

One of my coworkers has created a backend application using Spring Boot. Strangely, I can only access the API when both our computers are connected to the same hotspot. If I try to access the other computer's API and port through a browser or Postman, ...

Is there a way to manipulate the src value using jQuery or JavaScript?

var fileref = document.createElement('script'); fileref.setAttribute("type","text/javascript"); fileref.setAttribute("src", "http://search.twitter.com/search.json? q="+buildString+"&callback=TweetTick&rpp=50"); ...

Issues with form rendering in a Vue.js component

I have recently started learning vue.js and I'm trying to create a basic form using the materializecss framework within a component. The form requires this jQuery snippet to function: $(document).ready(function() { M.updateTextFields(); }); ...

Express.js - Monitoring for server closure

I have a Node.js application that utilizes Express. Within this application, there is a section of code structured as follows: const app = require('./app'); const port = process.env.PORT || 8080; const server = app.listen(port); server.on(&apos ...

Pass a URL string to a different script using Node.js

Currently, I am delving into the world of Node.js, utilizing Express with Jade and Mongoose as my primary tools. Originating from a background in PHP, transitioning to Python, and embracing MVC principles through Django, my aspiration is to create a multip ...

Set up ExpressJS to utilize port 3000 for the server

I am working on an app where the backend is currently running on localhost:8000, but I need it to run on port 3000. Specifically, I am using an express server for this example. How can I configure it to run on the desired port? Below is my current server. ...