Borgar.net

— Go straight to page navigation

05. August 2009

CSS :target

jQuery (or Sizzle) supports :target in browsers where it runs querySelectorAll to handle the work. In older browsers, it doesn't offer fallback support. I guess that this is simply because :target is such an uncommon selector?

I have no idea why you would want to use it, but because I have this selector extension and nowhere to put it, here it is:

jQuery.expr[':'].target = function ( a, h ) {
  return (a.id && (h = document.location.hash) && h === '#' + a.id)
};

Updated 6. aug. 2009: Optimized by @maranomynet

Published: 05. August 2009. Tagged: , , , .