Retrieve Element By Class Name in JavaScript

How can I modify the border color at the bottom of the .arrow_box:after?

Javascript Solution

document.getElementsByClassName("arrow_box:after")[0].style.borderBottomColor = "blue";

Despite trying this solution, it seems to be ineffective!

For a closer look at the issue, feel free to visit this example on Fiddle.

Answer №1

JavaScript cannot directly modify the styles of pseudo elements like :after or select them because they are not technically part of the DOM tree.

One workaround is to add another class to the element, as shown below:

document.getElementsByClassName("message_bubble")[0].className = "message_bubble highlighted";

.message_bubble.highlighted:after {
    background-color: yellow;
}

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

Error receiving parameter in express route callback function

At the moment, I have been working with a number of routes in Express. Some routes are quite lengthy and tend to look like this: router.get('/api/comments', function(req, res, next){ Comment.find({"user": req.payload._id}).exec(function(err,co ...

Tips for successfully passing a parameter to the --world-parameters or npm run command for it to be utilized by scripts within the package

Although there are similar questions already asked, I still have a specific scenario that I need help with: In the example I am working on, I am using this repository and I have a script block in my package.json as follows: I want to be able to pass a pa ...

Swap out all hyperlinks on the webpage with a different URL

I am looking to update all links in a specific style with new ones. I want to streamline the download process for Google Drive links. https://drive.google.com/file/d/1cCIWJMBOX-NvzYVTQajaVo5lNknYA2E8/view?usp=sharing My plan is to extract '1cCIWJMBO ...

Is it possible to deselect a checkbox if a radio button is selected, and vice versa?

I'm presenting these two options: <div class="pricing-details pricing-details-downloads"> <h4>Single purchase (60 lessons)</h4> <h4>Bulk Purchase: Lesson</h4> <div class="pricing-details-separator">&l ...

A script page in Wordpress generates a numerical value in the URL

I created a script named search.php which utilizes various search engines APIs to display search results. From this file, I have developed a Page template and incorporated the simplePagination plugin The issue arises when I click on a page within the pag ...

What is the best way to merge setInterval with mouseenter events?

I have successfully implemented code that refreshes a div using ajax. However, I am looking to add functionality so that the div only refreshes every 30 seconds when the tab is active. It seems that setInterval currently refreshes the div regardless of tab ...

NumericError on /post_create/ unrecognizable numeric value: 'manish'

I have a unique vision: I want to create posts with different authors in separate models def post_creation(request): author, initiated = Author.objects.get_or_create(name=request.user.username) form = CreationForm(request.POST or None , request.FILES or ...

Ways to prompt the debugger to pause whenever a specific script file is called during execution in Edge/Chrome debugger

I am currently in the process of debugging a Typescript web application, which is quite new to me as I have never delved into web development before. This particular project entails multiple script files and various libraries. While running the applicatio ...

Transmit a communication from a customer to the server

I have created a NodeJs server that is listening on port 1234. I am looking to send requests from my HTML client to this server and receive responses. I attempted to use XMLHttpRequest: var http = new XMLHttpRequest(); var url = "127.0.0. ...

Sending a JavaScript array to an MVC controller in .NET 5.0 via a POST request

Trying to send data from a JavaScript array to an MVC controller. While debugging, I end up in the method public void GetJSArray(List<SelectorModel> selectorModels) However, the selectorModels is currently showing as null. Below is the model being ...

Clicking a button will bring back the component to its assigned ID

How can I dynamically add a component <SaveTask/> to a specific div tag with the id of <div id="saveTask">? When I use this.setState(), it replaces the container and displays only the <SaveTask/> component. However, I want to re ...

Switch between different table rows

I have here a table that is used for displaying menu and submenu items. It's a mix of PHP (to fetch the menu items and their respective submenus) and HTML. What I am trying to figure out is how to toggle the visibility of only the submenu items under ...

Changing the information of objects stored in arrays using React Three Fiber

My challenge is with an array of roundedBox geometry shapes called myShape. I am trying to figure out if it's possible to change the position of one of the shapes within the array without creating a new shape altogether. Ideally, I would like to updat ...

Changing button alignment using CSS to create a new line

Currently, I am working on a React project using Material-UI where I am trying to create a numpad. The code snippet below showcases part of my implementation: // some parts are omitted for conciseness const keys = [7, 8, 9, 4, 5, 6, 1, 2, 3, 0]; ...

JSON response is not being successfully passed in PHP Ajax form validation

I've been struggling to solve my code for the past few days but haven't had any success. I'm attempting to validate my login form using AJAX, however, it seems like there's an issue with my Jquery AJAX script. Every time I try, the con ...

Position footer at the bottom of the webpage and adjust the height to be filled with main content using Bootstrap 4

I am currently in the process of designing a bootstrap layout that includes a header navbar along with a footer. My goal is to ensure that the footer is always at the bottom of the page, even if there is limited content. Here's what I have implemente ...

Is there a way to cross-reference a city obtained from geolocation with the cities stored in my database, and if a match is found, send the corresponding ID

Here's the script I'm currently working with: <script type="text/javascript"> search = new Vue({ el: '#offers', data: { data: [], authType: '{{uid}}', key : '1', wi ...

Analyzing viewer engagement by monitoring the duration of video watched using JavaScript

I need a way to monitor video views for individual users, using a table in the database called Viewings. Each viewing is associated with both a user and a video, and keeps track of the duration watched as well as the percentage of the video completed. Whe ...

The error message "SharedArrayBuffer is not defined" occurred when attempting to utilize ffmpeg.wasm

<!DOCTYPE html> <html> <head> <title>TikTok Live Downloader</title> </head> <body> <h1>TikTok Live Downloader</h1> <label for="username">Username:</label> ...

Node.js encountered an SFTP error stating "Error: connect: An existing SFTP connection is already defined."

Working within my node.js application, I have implemented ssh2-sftp-client to upload an image every 5 seconds. The initial upload functions correctly, but upon repeating the process, I encounter an error message: node .\upload.js uploaded screenshot ...