jQuery first child of “this”

I’m trying to pass “this” from a clicked span to a jQuery function that can then execute jQuery on that clicked element’s first child. Can’t seem to get it right…

<p onclick="toggleSection($(this));"><span class="redClass"></span></p>

Javascript:

function toggleSection(element) {
  element.toggleClass("redClass");
}

How do I reference the :first-child of element?

11 Answers
11

Leave a Comment