I want to select an element by its class, and assign it to a variable, but I want that element to be a heading element. Let me explain: at any given time, there will be exactly 3 elements with this certain class on my page: an <a>, a <p> and a heading element of unknown type, e.g. <h1>, <h2>, etc.
Selecting the <a> and <p> is easy, i.e. $("a.myclass"), but I cannot do that with my heading element. I need something like this:
var a = $("a.myclass");
var p = $("p.myclass");
var heading = $(some selector to get the heading);
Help please!
Also, I am aware that the title of this question isn’t a good one. If you so wish, please edit it and reword it.
You can use the :header selector – http://api.jquery.com/header-selector/
It will select all header elements, for example h1, h2, h3…
You can also use this as a filter if you only want header tags with a particular class, for example: