-2

I want to trigger a function when clicking a :after

For example

.foo:after{
    content: "read more";
}


$('foo:after').click(myFunction);

Will this cause any fuzz?

Himmators
  • 13,568
  • 33
  • 122
  • 214

3 Answers3

1

You cannot detect or trigger events on pseudo-elements as they are not part of the Document Object Model.

Also see Only detect click event on pseudo-element

Community
  • 1
  • 1
rink.attendant.6
  • 40,889
  • 58
  • 100
  • 149
1

Yes, :after is a pseudoselector which isn't part of the dom.

Tdelang
  • 1,267
  • 2
  • 12
  • 20
1
$('foo:after')

Sorry, but this won't work. The :after pseudo-element is not available to your Javascript code.

Spudley
  • 161,975
  • 39
  • 229
  • 303