-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
  • 14,278
  • 36
  • 132
  • 223

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
  • 44,500
  • 61
  • 101
  • 156
1

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

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

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

Spudley
  • 166,037
  • 39
  • 233
  • 307