Error while animating with jQuery

It's the wee hours of the morning and my jQuery skills are not the greatest. Can anyone point out the silly mistake I'm making?

I've created a JSFiddle for easy access: http://jsfiddle.net/JamesKyle/7GWRp/

Due to an issue with CSS transitions not working on :before or :after elements, I am attempting a workaround using jQuery which is already implemented on the page. The goal is to animate three CSS states - normal, hover, and active.

(Specifically, I want to animate the small shine at the top)

$(document).ready(function() {

    $('.button:before').mouseover(function() {
        $(this).animate({
            left: '0px',
            opacity: 1
          }, 100);
    });
    $('.button:before').click(function() {
        $(this).animate({
            left: '30px',
            opacity: 0
          }, 100);
    });
    $('.button:before').mouseout(function() {
        $(this).animate({
            left : '-30px',
            opacity : '1'
          }, 100);
    });

});

Answer №1

According to the insight provided here, it is concluded that pseudo elements cannot be directly targeted with jQuery since they are not part of the DOM.

An alternative solution suggested is to insert a physical element such as

<div class="button gray"><span></span>Button</div>
, although this may result in cluttering up the markup...

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

Initializing Access Model in Sails.js Service启

The inquiry: In the context of sails.js, it appears that Services are initialized before Models during the initialization process. Is there a way to alter this sequence? Can Models be loaded before Services? If not, then how can one retrieve specific se ...

Is it possible to invoke a JavaScript function from within a CSS file?

Currently, I am focusing on developing responsive web design and looking for ways to avoid creating multiple versions of each page based on screen width variations. The struggle lies in managing font sizes effectively. While attempting to style them using ...

What is the best way to create a point within a mesh?

I have several meshes and I'd like to insert a point randomly within the confines of hexagon[0]. How can this be achieved? var Hexagon=new Array(); Hexagon[0] = new THREE.Mesh( HexagonExtrude[0],material[0] ); Hexagon[1] = new THREE.Mesh( HexagonExtr ...

JavaScript innerHTML not functioning properly when receiving a response from a servlet

Can someone help me troubleshoot the code below? I'm receiving a response from the servlet, but I can't seem to display it inside the div. Here is the response: lukas requests to be your friend &nbsp <button value="lukas"onclick="accfr(th ...

JavaScript: Different ways to utilize the reduce method

Creating an array for search purposes based on a string like BBC Sport, the desired output array will be: [ 'BBC', 'BB', 'B', 'Sport', 'Spor', 'Spo', 'Sp', 'S' ] An implement ...

Sharing Data Between Controllers in AngularJS

I am faced with a challenge involving two Angular controllers: function Ctrl1($scope) { $scope.prop1 = "First"; } function Ctrl2($scope) { $scope.prop2 = "Second"; $scope.both = Ctrl1.prop1 + $scope.prop2; //Ideally, I would like to achieve t ...

The Ajax textbox is not providing any automatic suggestions in response to the typed

Having trouble setting up an auto-suggestion AJAX box as there seems to be no response from the server. <!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <head> &l ...

AngularJS encountered an unidentified provider: $routeProviderProvider

I've hit a roadblock with an unfamiliar provider error and can't seem to figure out what I'm missing. Here's the setup: in main.js 'use strict'; angular.module('myApp') .controller('MainCtrl', ['n ...

Guide to implementing the get method to parse URL parameters upon button click in a NodeJS, Express, and Mongoose application

I'm currently working on displaying data from a database in a table based on a list of cities. These cities are listed in a select option dropdown. I have successfully managed to retrieve the selected city value in the URL using a form with the GET me ...

Activate function at timed intervals

I've created a function that moves to the next slideshow image when a user clicks a link: jQuery("a.next").click(function(e) { return ngg_ajax_navigation(e, this); }); Now, I want the image to advance automatically every 3 seconds as well. What& ...

How come my header is not spanning the full width of the page?

Hey there, I've been struggling with a specific issue on my website and can't seem to find a solution anywhere else. The header on my site is supposed to stretch across the entire width of the screen, but for some reason, there's always a ga ...

Troubles with retrieving Array data for a JavaScript column chart

I am currently developing a Flask app in Python and utilizing render_template to send back 2 arrays, "names" and "deals", to my HTML file. I have confirmed that these arrays are working correctly based on the code snippet below that I tested, which display ...

Puzzling blank area found beneath the form component

There seems to be some extra space at the bottom of a form when it's placed inside a div. How can we remove that unwanted space? In examples from stack overflow, the extra space is not visible in the code snippets provided. However, it appears elsewh ...

Sending a POST request using Node.js XHR

I am currently utilizing nodejs to send a POST command to a server. In this process, I am also making use of the node-xmlHttpRequest module created by driverdan. However, I am encountering a problem related to the content-type setting, which is resulting i ...

"Basic npm module that does not come with any CSS code, featuring a React component that

I am working on developing a small and straightforward npm package that leverages react. The challenge I'm facing is the need to import the CSS file from the dist folder and have it automatically imported with the export. Is this achievable? import Re ...

Executing function inside an Angular factory

I am currently working with an Angular factory that contains various functions. My goal is to use myService to retrieve data, and upon successful retrieval, call another function within the factory: myApp.factory('myFactory', function($http) { ...

Having trouble implementing custom fonts in React App for all browsers

While working on my project, I included custom .woff fonts using @font-face and stored them in my src folder. Surprisingly, the fonts displayed correctly when running the app locally. However, upon deploying the app to the live domain, Chrome and Firefox ...

Generating hierarchical structures from div elements

Looking for guidance on how to parse a HTML page like the one below and create a hierarchical Javascript object or JSON. Any assistance would be much appreciated. <div class="t"> <div> <div class="c"> <input t ...

Tips for displaying a React component with ReactDOM Render

_Header (cshtml) <div id="Help"></div> export default class Help { ReactDOM.render( <Help/>, document.getElementById('Help') ); } Help.js (component) } My objective is to di ...

Angular pipe with Observable request to filter HTML content

Async pipes are commonly used to subscribe to observables and receive updated values. However, I am in the process of creating a custom pipe that translates a classification using its code asynchronously. Is there a way to wait for the async action to comp ...