Is there a way in javascript to select a selector within another selector like in jQuery:
$("section h1").html();
Is there a way in javascript to select a selector within another selector like in jQuery:
$("section h1").html();
jQuery actually uses querySelectorAll when available. Thing is, on your own, you'll never be able to emulate all the goodies that jQuery provides (e.g., filter(), find(), children(), parent(), map(), not() and the ability to use pseudo-classes).
This would be enough to grab the h1 element in section:
var e = document.querySelector("section h1");
Read on this answer https://stackoverflow.com/a/11503576/2612112.
Closest you'll find is probably document.querySelector or document.querySelectorAll. Should be careful though, as support is limited to modern browsers.
you also could do the following... however there are easier ways
see jsfiddle http://jsfiddle.net/kasperfish/CR5EX/2/
alert('jquery '+$("#section h1").html());
v=document.getElementById("section").getElementsByTagName("h1");
alert('javascript '+v[0].innerHTML);
` within a ``.
– Justin K Sep 26 '13 at 20:33