idea
Via jQuery, I was able to mark all :first-child
and :last-child
elements in document (well, almost all :)) with class first
which could I later style (i.e. first li in ul#navigation
would be easily adressable as ul#navigation .first
).
I used following code:
var $f = $('*:first-child')
$f.addClass('first');
var $l = $('body *:last-child')
$l.addClass('last');
example
Example is already here - it's not the way to do it however, it's just an idea prototyped in other, for me at the moment easier language.
question
Now, my question is if it's possible to do the same via php
, so non-JS users/gadgets could have the same effects and additional styling and also it would be less overkill on browser.
So, is it possible to capture output, parse it as html and inject this class easily in php
?
clarification
I'm quite aware of output buffering
, just haven't done much stuff with it - also, i'm not sure about modificating output string
in php
as parsed dom (without regex
) - and how tough on server it'll be - with caching of course, so this whole stuff will run once until the page will be edited again.