David Walker | 11 July 2012
"Ahh says the delegate you use:"
"What about selecting all <p> in the HTML?" Say I.
Hmmm the student ponders further.
The strongest among them says "we would select the <div>'s then select <p>'s from the <div>'s." They are strong! I am proud! Yet there is much to learn.
"The solution you have suggested is arduous my friend, it involves nested and recursive loops and like Kane leaving the temple of Kung Fu the scars you will carry will haunt you for the rest of your days."
"Let me make you faster and stronger."
document.querySelectorAll('div > p');
With a call to console.dir(); I prove that I am still the master, but our day of ultimate reckoning draws closer.
The delegate is humbled yet enlightened so I task them with one more question."The"<p id="intro"> I spoke of. I have removed its ID."I laugh an evil Kung-Fu laugh."It is the first paragraph in the document. FIND IT!" I command!"
Suddenly the delegate leaps into action and proclaims:
"I have realised Master Dave that the CSS3 Selectors are useable here!"
I bow, touch one clenched first to an open palm. "This is true, it is faster, more efficient and less code heavy. It makes your syntax easier to read for designer and developer."
"Then why Master Dave do we still use document.getElementById() ?" I turn with a look of cold determination."For IE7 and below do not understand these new selectors and IE 8 s flabby and weak."Turning with grim determination I proclaim,"To tame them we shall turn to the magic of jQuery!"
Then the CSS Ninjas attacked!