Switching the class for the pseudo-element :after

Consider a scenario where there is a button:

<button href="#" class="search  no-style search-active" style="display: inline-block;">
 <div class="pointer" style="display:none">::after</div>
</button>

Upon activation of the button, the pseudo-class :after should have the class search-active toggled in order to define a background color for the button.

.primary .search:after,
.primary .search[data-search="disabled"]:after {
  color: #fff;
  content: "\E8B6";
  font-family: "Material Icons";
  position: absolute;
  top: -25px;
  transition: color .3s;
  font-size: 26px;
  margin-left: -10px;
}

//THIS NEEDS TO BE APPLIED TO THE :after PSEUDO CLASS TO SET THE BACKGROUND COLOR OF THE BUTTON
.search-active {
  background-color: purple;
  padding: 12px 33px 19px 35px;
  margin: 0px -30px;
}

There is existing jQuery functionality that works with another button but does not seem to be effective in this particular case:

$(".search").on("click", function() {
  $(this).toggleClass('search-active');
});

JSFIDDLE:https://jsfiddle.net/xk9hx9j9/2/

Answer №1

Your input is crucial; delete the following "//THIS SHOULD BE INCLUDED IN THE :after PSEUDO CLASS TO ASSIGN THE BUTTON'S BACKGROUND COLOR"

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

Is this method an effective way to create global states across React components?

After delving deep into props-drilling while coding a full-fledged web application with React, I've decided to explore using React 'contexts'. Following the guidelines in the React documentation, I am implementing an approach to make my stat ...

Exploring the possibilities of implementing the .map() function on a JSONArray within a ReactJS project using ES

When I receive a JSONArray from the server, my goal is to use .map() on it in order to extract key-value pairs of each object within the array. However, when I try to implement this code, I encounter an error stating "files.map is not a function". Can some ...

What is the best way to update only a portion of a nested schema in mongoose?

UPDATE: Through numerous trials, I finally discovered a successful method that converts any object into a format that mongoose can interpret. Take a look at the solution provided here: const updateNestedObjectParser = (nestedUpdateObject) => { cons ...

Material Design Autocomplete search feature in Angular 2

I'm encountering some challenges with autocomplete in Angular2 Material Design. Here are the issues I'm facing: 1. When I type a character that matches what I'm searching for, it doesn't display in the autocomplete dropdown as shown in ...

What is the best way to update the content of a particular div and its associated link ID whenever the link is clicked?

I need to update the content of a div by clicking on an href link that includes an id named data. The issue I'm facing is that I can't access the id value within my script because it's passed within a function. How can I pass the data variab ...

I attempted an AJAX script, but unfortunately, it was unsuccessful. Upon submitting the form, I received a success alert, but no data was sent to

I have been struggling with an Ajax script that doesn't seem to be working as expected. When I submit the form, I receive a success alert but nothing is being sent to the database. Here is my HTML form: <form action="account_info.php" enctype="mu ...

The Move-class only applies to items within a transition-group that have not been removed if other items were removed

My item list is displayed in a flex-box, forming a matrix with several rows and items per row. I use the <transition-group class="move"> to apply a simple move transition to the <div v-for="item in items" :key="item.id"> move { transition: t ...

The tooltip of the Material UI IconButton is displaying incorrectly

Within my ReactJS application, I am utilizing Material UI along with react-bootstrap-table components. One particular cell in my application utilizes the Material UI IconButton as shown below: <IconButton tooltip={t('tooltips:editRegulation&apos ...

What is the best way to terminate a MongoDB client connection in the event of an error?

I am currently managing a configuration where I have set up a MongoDB instance and operating two JavaScript services on a Linux server. One of the services, moscaService.js, is responsible for listening to MQTT topics on the server and storing the incoming ...

Is it appropriate to invoke componentWillReceiveProps within the componentWillMount lifecycle method?

I'm new to working with react and I have a question. How can I call a function within another function? For example, I want to call componentWillReceiveProps inside of componentWillMount. How can I achieve this? import React from 'react' cl ...

Retrieve AJAX images but experiencing issues with jQuery click function

In the index HTML file, I have 7 images. I have implemented a jQuery function that gets the ids of the images when they are clicked. The jQuery function looks like this: $(".imgss").click(function() { alert($(this).attr("id")); }); I assign the clas ...

What causes the inconsistency between Chrome's print CSS emulation and the Print Preview feature?

My website is based on Bootstrap 3 and ensuring that certain pages print properly is crucial for our customers. While most of the site prints fine, we are having issues with modal dialogs. I have been experimenting with Chrome's (v42.0.2311.135 m) CS ...

Unable to make an ajax request due to github.io's restrictions

I am facing an issue with all my apps that have ajax requests, as they are returning errors stating: "This request has been blocked; the content must be served over HTTPS." An example of this error can be seen at https://zzharuk.github.io/local_weather_w ...

Using Node and Express to handle form submissions, we can create a POST request that sends data to the server

Despite my ongoing learning journey, I am feeling a bit frustrated as I struggle to find a solution for this particular issue using ES6 Javascript. Currently, I have a straightforward todo-list web-app where everything is managed and displayed through the ...

Unable to locate the value of the query string

I need help finding the query string value for the URL www.example.com/product?id=23 This is the code I am using: let myApp = angular.module('myApp', []); myApp.controller('test', ['$scope', '$location', '$ ...

A guide on encrypting the data of a file that is uploaded in Meteor.js

As a newcomer to Meteor and coding in general, I have completed tutorial projects and examples and now feel ready to start my own project. I want users to be able to select a file from their computer using an input field, read the contents of the file, and ...

Iterate through a loop to assign values to an object, then transform it back into an object

My goal is to create a Component with a child that could be any component, so I need to assign the props to this Component. I attempted to do this in a loop because I am unsure about the number of props that should be assigned. //Array of objects that I w ...

Issues with overlapping floating labels in Bootstrap 5

Is there a way to display longer text without it being cut off or truncated, especially in input fields where the full content is necessary for clarity? It can be frustrating when only part of the text is visible. This issue arises from the Bootstrap 5 e ...

I am experiencing an issue with using double quotation marks in VS Code

Whenever I press the double quote symbol like this "", the cursor automatically moves to the end. While this may be natural, I would prefer the cursor to move inside the double quotes automatically when pressing them. Additionally, it's a bi ...

Creating an object based on its type in JavaScript is a simple task

In a recent project, I found myself using the following code: function foo(type, desc) { var p = new type(desc); } Although I am not a JavaScript expert, it seems to be functioning properly in Chrome. Can anyone confirm if this is valid JavaScript? Th ...