Exclude cascading classes in CSS

Help Needed with HTML Lists!

<li>A.</li>
<li><a href="#">B.</a></li>
<li><a class=tr href="#">C.</a></li>
<li class=tr>D.</li>
<li class=notr>E.</li>

I am trying to select all untranslated innerText.

document.querySelectorAll("li:not(.notr):not(.tr)")

The issue arises when the TR class is not present in LI, making it difficult to filter.

li:not(.notr):not(.tr)+li>a:not(.tr)
- results in an empty NodeList.

Although seemingly simple, this question has left me puzzled.

Answer №1

As mentioned in the previous comments, the key to resolving this issue is to initially retrieve the collection and then further refine the outcomes by applying an additional filter.

let rawresult = document.querySelectorAll("li:not(.notr):not(.tr)");

console.log('raw results:');
rawresult.forEach(el => console.log(el.innerText));

let refinedresult = [];
rawresult.forEach(function(el) {if (el.querySelector(".notr,.tr") == null) refinedresult.push(el);});

console.log('refined results:');
refinedresult.forEach(el => console.log(el.innerText));
<ul>
  <li>A.</li>
  <li><a href="#">B.</a></li>
  <li><a class=tr href="#">C.</a></li>
  <li class=tr>D.</li>
  <li class=notr>E.</li>
</ul>

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

Create multiple buttons with uniform width by adjusting padding in CSS

I recently attempted to create buttons using CSS and padding. Here is the HTML code for the buttons: <link rel="stylesheet" type="text/css" href="css/style-login.css" /> <link rel="stylesheet" type="text/css" href="css/font-awesome-4.0.3.css" /& ...

Challenges with the Placement of Buttons

I am facing an issue with the code below: document.addEventListener("DOMContentLoaded", function(event) { // Select all the read more buttons and hidden contents const readMoreButtons = document.querySelectorAll(".read-more"); const hiddenConten ...

Is there a way to utilize a MongoDB plugin to retrieve results directly as a return value instead of within a callback function?

I came across a MongoDB plugin for Node.js that always utilizes callback functions to return search results. However, I am looking for a way to receive the result directly without using callbacks. The code snippet below does not provide me with the desire ...

The sum is being treated as a concatenation instead of an addition in this case

Why is the somma value showing the concatenation of totaleEnergetico and totaleStrutturale instead of a sum? RiepilogoCombinatoStComponent.ts export class RiepilogoCombinatoStComponent implements OnInit { constructor() { } interventi: AssociazioneI ...

Encountering a "Cannot modify" error in wp-admin while using inspect element

It seems like there is a slight error appearing in the Inspect Element Source Tab of Google Chrome (also checked in Firefox). I have searched extensively for a solution but haven't found anything helpful. My Wordpress theme displays wp-admin in inspec ...

Utilize Javascript to reconfigure the JSON structure

Hey there, in my code I retrieve a JSON blob that has the following structure: [ { "ts": 1431736740, "aggs": { "DNS": { "min": 20, "max": 21, }, "SEND": { ...

Leveraging PapaParse for CSV file parsing in a React application with JavaScript

I am encountering an issue with reading a CSV file in the same directory as my React app using Javascript and Papaparse for parsing. Below is the code snippet: Papa.parse("./headlines.csv", { download: true, complete: function(results, f ...

When IntelliJ starts Spring boot, resources folder assets are not served

I'm following a tutorial similar to this one. The setup involves a pom file that manages two modules, the frontend module and the backend module. Tools being used: IDE: Intellij, spring-boot, Vue.js I initialized the frontent module using vue init w ...

Modify this tooltip feature to delay the hiding of the tooltip by x seconds

I have successfully created a tooltip using the following link: http://jsfiddle.net/GLZFc/ Currently, the tooltip works perfectly fine. However, I would like it to hide after x seconds of inactivity. Additionally, if I mouse over it again, I would like th ...

Creating a Google map with multiple markers within a 10 km radius of the current location in a rectangular shape

Currently, I am working on a web application that utilizes Google Maps and AngularJS. One of the requirements is to display multiple markers on the map, but only those within a 10km range from the corners, not in a circular radius. In order to achieve th ...

Add the scss file to the vuejs component npm package only if certain conditions specified in the project are met

Creating css/scss themes for my Vue Components Npm package has been a focus of mine lately. This particular package is local and currently being tested using npm link. Both the Package and Project are utilizing webpack. index.js of Package import "./src ...

I'm puzzled as to why the background isn't fully covering all of the content on the page

As an IT student, I have been diligently working on creating a website for my assignment. However, I am facing an issue with the background not adjusting properly based on the content placed within it. While one page includes all the sub-divs as intended, ...

Utilizing use-immer and promises to effectively handle an API route mapping system

In the process of tackling the issue of double hook calls in Next.js dev mode, I've encountered a challenge with server API calls that cannot handle duplicates. To address this, I opted for fix #4 outlined in the following article, where I decided to ...

Using Axios with Node.js throws an error: "ReferenceError: XMLHttpRequest is not defined."

When sending a GET request using a basic axios configuration, I encounter the following issue: var Axios = axios.create({ baseURL: myBaseUrl, headers: {'content-type': 'application/json'} }); Axios.get(url) The er ...

Create a CSS border with a stylish downward arrow design

Recently, I came across a specific requirement that I need help with. You can see the image https://i.sstatic.net/j4Qdf.png. I found a helpful resource on how to create triangles using CSS on https://css-tricks.com/snippets/css/css-triangle/. However, I a ...

Customize the appearance of every other column in an asp gridview

Looking for help with formatting rows and columns in an ASP GridView. The rows are automatically colored alternating, and I want to make the content in every first column bold and every second column normal. I have heard about using CSS nth-child() to achi ...

Issue with Ajax post redirection back to original page

I'm facing an issue with my ajax call where I send multiple checkbox values to a php file for processing and updating the database. The post request and database updates are successful, but the page doesn't return to the calling php file automati ...

Strange interaction observed when working with Record<string, unknown> compared to Record<string, any>

Recently, I came across this interesting function: function fn(param: Record<string, unknown>) { //... } x({ hello: "world" }); // Everything runs smoothly x(["hi"]); // Error -> Index signature for type 'string' i ...

"Using regular expressions in a MongoDB find() query does not provide the desired

app.get("/expenses/:month", async (req, res) => { const { month } = req.params; const regexp = new RegExp("\d\d\d\d-" + month + "-\d\d"); console.log(regexp); const allExpenses ...

Updating HTML Pages with Dynamic Content

Dealing with a massive project consisting of 50,000 pages (20,000 aspx forms, 10,000 asp forms, and 10,000 html pages) can be overwhelming. With only 2 days to complete the task of adding content after the body tag on all pages, I am seeking advice on ho ...