Is there a way to target the mat-icon element using the icon's name in CSS

I have a group of mat-icons that are automatically generated, meaning I cannot assign them ids or classes. The only way to distinguish between them is by their names:

<mat-icon role="img">details</mat-icon>
<mat-icon role="img">edit</mat-icon>
<mat-icon role="img">delete</mat-icon>

My question is, can I target and style only the "delete" icon without affecting the others based on its name? Is this possible?

Answer №1

Short answer: unfortunately No!

Long answer:

The code snippet

<mat-icon role="img">delete</mat-icon>
will convert at runtime to something like this

<mat-icon 
class="mat-icon notranslate material-icons mat-icon-no-color"
role="img" aria-hidden="true">delete</mat-icon>

Upon closer inspection, it is evident that there are no useful identifiers (such as class names or data properties) within the element that can be targeted using CSS selectors. The only distinguishable information resides in the text content of the element which cannot be utilized for selecting elements as per the specifications.

There have been discussions about introducing the :contains() selector but it never materialized.

BONUS:

If all else fails, resorting to JavaScript/TypeScript may be the solution:

let editIcons =[].filter.call(document.getElementsByTagName('mat-icon'), 
el => el.innerText=="edit");

editIcons.forEach( e => {
e.style.color = "red";
});

https://i.stack.imgur.com/qKOs4.png

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

Adjust the size of a div element dynamically to maintain the aspect ratio of a background image while keeping the

Utilizing the slick slider from http://kenwheeler.github.io/slick/ to display images of varying sizes, including both portrait and landscape pictures. These images are displayed as background-image properties of the div. By default, the slider has a fixed ...

Creating multiple CRUD components in Angular 2: which is better, using routing or a parent component

My application consists of multiple sections that act as independent CRUD components. There are two approaches that I am aware of: Utilize a parent component with ngIfs to manage the view/edit/add operations of child components Implement subrouting wit ...

Displaying an item in the menu based on a condition in React

Currently, I'm utilizing React in combination with Material-UI for my project. I am working on creating a dropdown menu within the UI, and I am looking to have control over rendering the first row based on a condition passed as a prop. Can anyone prov ...

Include the circle.css file in the Angular 4 project by loading it in the head section of the

I am currently working with Angular 4 and would like to incorporate the circle.css styles from cssscript. After downloading the file from the provided link, I placed the circle.css within my something component file. However, when attempting to use &l ...

Is there a way in NodeJS to preview the contents of a file in a browser before initiating the download process?

Is there a way to preview a file in the browser before downloading it in NodeJS? This would allow users to make sure they are choosing the correct file to download. Currently, I have this code for downloading a file: app.get("/download/file", (req, res) = ...

Scraping Secrets: Unraveling the Art of Procuring User Links

I need assistance with extracting links from the group members' page on Meetup: response.css('.text--ellipsisOneLine::attr(href)').getall() Can you please help me understand why this code is not functioning correctly? This is the HTML stru ...

Handling a change event for a mat-datepicker in Angular 7 can be tricky, especially when its value is tied to an optional input parameter. Let's dive into how to

I've recently started working with angular development and encountered a challenge with a mat-datepicker. The value of the datepicker is connected to filterDate using [(ngModel)] as an @Input() parameter. I have implemented a handleChange event that e ...

What is the best way to showcase two data frames side by side in an HTML template or webpage without using frames?

Is there a way to showcase two data frames side by side in an html template? <h3> TITLE </h3> {{stat1 | safe}}. {{stat | safe}} I attempted the above solution, but unfortunately it only displays the data frames vertically stacked instead of ...

Incorporating Google's Invisible Recaptcha with Jquery Ajax and PHP

I am struggling to make my form, which includes Google invisible reCAPTCHA, work seamlessly with my jQuery AJAX and PHP. It appears that the token is not being properly sent to my PHP page via AJAX, resulting in the following error message from my PHP scri ...

PHP contact form not properly sending complete submission data

I'm facing an issue with my HTML contact form that utilizes JavaScript for a change function. Essentially, I have a dropdown menu for different subjects, and based on the selected option, specific fields should appear. However, when a user fills out t ...

Toggle the font weight in a text area by clicking a button

I need help with creating a button that will change the font-weight to bold when clicked and then revert back to normal when un-clicked. However, I only want the specific part of the text area where the user clicks the button to be bolded, not the entire t ...

Tips for solving the error "Angular CLI version 7.0.3 cannot install node-sass"

Every time I attempt to run npm start, an error message stating that it cannot find the module node-sass appears. Then, when I try running npm install node-sass --save, a series of errors pop up. https://i.stack.imgur.com/2I7DU.png ...

Exploring the benefits of using Div and semantic elements in web

After spending more than two months learning HTML, I still find myself uncertain about the most practical coding approach. Despite knowing that it's important not to overthink it, I often wonder if I should stick with simplicity or add extra elements ...

"Classes can be successfully imported in a console environment, however, they encounter issues when

Running main.js in the console using node works perfectly fine for me. However, when I attempt to run it through a browser by implementing an HTML file, I do not see anything printed to the console. Interestingly, if I remove any mentions of Vector.ts fro ...

Jquery problems impacting every element rather than only one

I'm currently experimenting with a small project where I have multiple div elements containing an image, h1 tag, and p tag all sharing the same class name. My goal is to add CSS effects that make the h1 tag and p tag slide into view and become visible ...

Tips for planning a showcase arrangement in React Admin with the help of a Material UI Grid

In my new React-Admin project, I have set up several Show views. Instead of having the fields in a single column layout, I want to use Material UI's Grid component to create a more efficient and user-friendly arrangement. However, when I try to implem ...

Customizing MUI radio buttons to display tick icons instead of bullets

Looking to replace the bullet icon with CheckCircleSharpIcon from '@mui/icons-material/CheckCircleSharp' {res?.map((radiooption, index) => ( <> <RadioGroup aria-labelledby="demo-radio-buttons-group-label" name="radio-bu ...

The integration of cypress-cucumber-preprocessor with multiple testing frameworks appears to be experiencing compatibility issues

I am trying to set up a connection between Cypress and Cucumber, and I came across this plugin: https://www.npmjs.com/package/cypress-cucumber-preprocessor However, I am having trouble with my implementation as it seems to be missing. I have also added th ...

The mouseenter event in jQuery is failing to trigger

I'm encountering an issue with the mouseenter event on a div section of my webpage. I am attempting to alter the background color of this div when the mouse enters, but it seems to be disregarded. This is the basic HTML code: <div id="services" c ...

Hover over the first element to remove its class and replace it with a different element

I am attempting to develop a function that adds the class = "actived" to the first Element. This class has a CSS style that highlights the element in question. I have a list of 4 lines and I want the first one to automatically receive this class, while t ...