Jump to content


Photo

Target the last image and apply a class to it

images

  • Please log in to reply
1 reply to this topic

#1 tinacious

tinacious

    Full Member

  • Members
  • PipPipPip
  • 66 posts
  • 33

  • LocationToronto, Canada

Posted 03 June 2012 - 09:09 AM

Hi everyone,

I would like to target the last image in the fieldset and apply a specific class to it. How would I do that?

I've tried this and it applies it to all:

if(($page->images->last()->name) == 'whatsnext.png') { echo $whatsnextclass; }

It's not targeting that specific image, it's just checking to see if that exists. I don't know how else to go about this. Help please?

Thanks!

#2 diogo

diogo

    Hero Member

  • Moderators
  • 1,974 posts
  • 1059

  • LocationPorto, Portugal

Posted 03 June 2012 - 10:21 AM

This should do what you want
//inside a foreach($page->images as $image)
if($page->images->last() === $image) { echo $whatsnextclass; }






Also tagged with one or more of these keywords: images

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users