Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 676357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:55:08+00:00 2026-05-14T00:55:08+00:00

idea Via jQuery, I was able to mark all :first-child and :last-child elements in

  • 0

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

http://jsbin.com/ikuca/3

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:55:08+00:00Added an answer on May 14, 2026 at 12:55 am

    I’m sure you could use output buffering to capture your assembled PHP page and then use DOM and XPath on it to add the class attributes, but the question is, why don’t you just put the classes onto the elements when assembling the page in the first place? Saves you the jQuery and the capturing.

    Also, adding the CSS classes with jQuery to be able to do ul#navigation.first is somewhat odd too, because the jQuery expression you used is a CSS selector, so you could use it directly to style the first child from your CSS file. The only reason to add a class .first is if you want to be backwards compatible with browsers unable to process :first-child.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I am retrieving JSON entities via jQuery from the server and manipulating them
I have a web app. that uses AJAX (via jQuery). I noticed that some
I have a form, in which I need to send data selected via AJAX
I have a scrolling DIV that via JQuery determines the element in the middle.
I have a input form element which I will like to be able to
I'm reading an xml file with PHP and pulling it into jQuery via a
I'd like check via jquery a string, thi string can begin by P or
i have a page loaded via jquery tabs ajax, i have a form within
so i have form that I am submitting via jQuery form's ajaxSubmit it was
I was wondering how to extract data from a returned object via jQuery's $.get()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.