Is it possible to customize the appearance of ordered list numbers using javascript?

Is it possible to change the color of a specific line number in an ordered list using JavaScript? I am familiar with CSS styling such as li::marker, but curious about altering individual list item markers dynamically through JavaScript. How can this be achieved?

If you have any insights or solutions, please check out this link:

Answer №1

If you want to make certain list items stand out, simply add a specific class to them.

document.querySelector('ol').children[1].classList.add('highlight');
li.highlight::marker {
  color: red;
}
<ol>
  <li>item</li>
  <li>item</li>
  <li>item</li>
  <li>item</li>
</ol>

You can also utilize the :nth-child() pseudo-class if you already know the order of the items in the list.

li:nth-child(2)::marker {
  color: red;
}
<ol>
  <li>item</li>
  <li>item</li>
  <li>item</li>
  <li>item</li>
</ol>

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

Assign properties to a component from an object

I'm working on connecting React Components to Objects by passing imported Components as Props. const [showComponent, setShowComponent] = useState([ { cId: 1, componentName: <ContactDialogAddresses />, title: 'Address', render: true ...

Selecting an option from dropdown1 to retrieve a specific value from a JSON file

I currently have 2 dropdown lists to fill with data from a JSON file: $scope.categories = [ {name:"Blouse", sizes:["36","38","40","42","44","46","48","50"]}, {name:"Shirt", sizes:["36","38","40","42","44","46","48","50"]}, {name:"Pants", size ...

How can I align two div buttons at the top and bottom to appear on the left and right sides?

How can I change the position of two buttons from top and bottom to left and right as shown in the second image? I am utilizing Floating Vue, so the buttons will be contained within a div. Is it feasible to adjust their position accordingly? Check out th ...

What could be the reason for data.map not being recognized as a function?

I developed the following React component: import React, { useState } from 'react'; export default function Example(){ var friend = function (id, firstName, lastName){ this.id = id; this.firstName = firstName; this.lastName = lastN ...

Tips for expanding the dimensions of a text box within the filter menu

In my application, I am using a kendo grid with filterable set to true. The filtering functionality is working properly. However, when I click on the filter symbol, the filter menu opens and I noticed that the size of the text-box within the menu is too sm ...

Here is how you can pass two callback functions to React.cloneElement:

Recently, I encountered an issue where one of the callbacks passed to a child component using React.cloneElement was always present while the other was undefined. Specifically, activeRow was consistently available but deactivateRow remained undefined. I ...

What is the best way to ensure that Bootstrap columns are spacious enough to fit advertisements?

Using Bootstrap 5, I have created a page layout with 3 columns: <div class="container"> <div class="row"> <div class="col-md-3">LEFT</div> <div class="col-md-6">CENTER</div& ...

How can you retrieve an array of multiple property values from a collection of dynamic objects?

I am currently working with a dynamic JavaScript object array that has varying structures. For example: var someJsonArray = [ {point: 100, level: 3}, {point: 100, level: 3}, {point: 300, level: 6} ]; At times, it may have a different combination lik ...

Custom Script for Single Tumblr Entry

While I know it's possible to edit the HTML/AngularJS for the overall posts on a Tumblr blog homepage, I'm wondering if there is a way to insert a custom <script>...</script> into individual posts. I have some specific JavaScript task ...

Passing asynchronous data to child components using an object in Angular6

Currently, I am facing an issue with displaying data retrieved from a server using Angular 6, Rxjs, and Chartjs. When utilizing local mock data, everything works perfectly fine. However, when fetching data from the server, the charts render as blank becaus ...

The behavior of AJAX Search varies between the development and production environments

I recently integrated an instant search feature into my application. During testing on the local server, the functionality met my expectations: It filters the list as I type It is not case-sensitive It allows for resetting the search if I delete the inp ...

By utilizing the <tr> element, one can enhance the border thickness by 1 pixel

Is it possible to ensure that row selection in a table is consistent in terms of border alignment on both sides? https://i.stack.imgur.com/qmZiQ.png If you have any suggestions or solutions, please share them. Thank you! table { margin: 10px; bord ...

Is there a way to automatically compile LESS files whenever I save a document?

After installing Less using npm with the command $ npm install -g less I currently compile my source files to .css by running $ lessc styles.less styles.css Is there a method through the command line to automatically compile the document when saving it ...

Shifting the final child to the front position proves unsuccessful with jQuery

I have attempted to move the last element in my list to the first position upon clicking, but unfortunately, it is not working as expected. I followed the advice provided in response to a question on the following page: Move last child to first position. W ...

PHP not able to retrieve JavaScript variable using Ajax

Resolved: I recently discovered that ajax only sends data in that particular moment, and redirecting creates a new instance. I spent hours searching through various Stack Overflow results for solutions, but none of them seem to work. My current challenge ...

Designing a solid sidebar of a specific width alongside a flexible container for content that adapts to different screen sizes using

I have a sidebar that is fixed at 200px on the left side of the page, and a responsive content container on the right side. To center the content in the right container, I used the following CSS: .sidebar { width: 10%; position: fixed; height: 100%; bac ...

Troubleshooting Problem with CSS Gradient Text

I'm attempting to recreate the text effect found here: . However, I'm facing issues getting it to work despite using the same code. This is the HTML I am using: <h1><span></span>Sign Up</h1> My CSS looks like this: h1 { ...

The props in Vue 3 are not functioning as expected in child components even after being bound correctly, resulting in undefined values in the child component

Exploring the realms of Vue and Laravel, I find myself in new territory. As the parent element, I fetch items from the database successfully. Now, the task at hand is to pass this data to the child component. <template> <div class="todoList ...

Determine the position of an element in relation to a specific ancestor using JavaScript

Let's consider the following example of HTML code: <div id="site_header_container" class="site_bar_container"> <div id="site_header"> <div id="header_logo_container"> <a class="sliced" id="header_ ...

Adjust the position of the select box slightly downwards to ensure it lines up with the preceding text in the HTML code

I am working on an HTML5 webpage and I am facing an alignment issue with the selection box. The selection box is currently not aligned with the text ("Select Discipline") that comes before it. I am looking for a way to adjust the position of the selectio ...