I’ve got this HTML structure:
<span id="subMenuTitle1" class="subMenuClickAble"><h2>Inbox 1</h2></span>
I want to attached a click event to span.subMenuClickAble and extra the text() in the h2.
I’ve tried to the following:
var text = $(this).child('h2').text();
var text = $(this h2).text();
Any advise?
Try this:
However, your HTML code is invalid (unless you are using HTML 5 and targetting only HTML 5 capable browsers), so the
h2element might not even end up inside thespantag.An inline element (
span) may not contain a block element (h2). Browsers will try to correct the code, usually by moving theh2element outside thespan, or ending thespanelement where theh2element starts.