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?
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.
::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.
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.
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With