Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .click() event for CSS pseudoelement (:before/:after)?

Tags:

I want to trigger a jQuery animation when content that I am inserting through the CSS pseudoelements :before: and :after is clicked. However, I'm not sure how to do this; my first guess, $(#id:before).click() didn't work. Is this part of jQuery's functionality? If so, how would I select the before/after content?

like image 404
daysrunaway Avatar asked Jul 01 '11 00:07

daysrunaway


People also ask

How can I only detect click event on pseudo-element?

Your answerThis is not possible; pseudo-elements are not part of the DOM at all so you can't bind any events directly to them, you can only bind to their parent elements.

What is before pseudo selector in CSS?

::before (:before) In CSS, ::before creates a pseudo-element that is the first child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.

How do you trigger a click element?

The HTMLElement. click() method simulates a mouse click on an element. When click() is used with supported elements (such as an <input> ), it fires the element's click event. This event then bubbles up to elements higher in the document tree (or event chain) and fires their click events.

What is the difference between .on click function ()) and .click function?

So onclick creates an attribute within the binded HTML tag, using a string which is linked to a function. Whereas . click binds the function itself to the property element.


1 Answers

jQuery does not support the CSS :before and :after selectors. To select siblings, use .siblings() and then filter from there.

http://api.jquery.com/siblings/

like image 125
Chris Laplante Avatar answered Sep 23 '22 06:09

Chris Laplante