Search code examples
cssxpages

XPages CSS and id-attributes


Normally I can get around the fact xpages hijacks the id-attribute on fields etc by using the x$ jQuery selector...

However, I'm building a sylesheet using the @print media query to make a normal form into a pretty version when printed. I have a scenario, where I have a custom control, have given it an ID of GuidanceArea, and under normal circumstances would be able to reference it in my style sheet with #GuidanceArea, just to simply hide it for example for this scenario.

However this isn't working, I assume because of the ID hijacking? It's not too much of a big deal, as I have workaround where for all elements I don't want to print I just append no-print to the elements styleClass and have .no-print set to display:none in my @media print within the style sheet.

However out of curiosity more than anything, I wondered if there's an easy way to get a hold of an elements ID for use in CSS?


Solution

  • The short answer: don't

    The longs answer: JSF and XPages manage the id attribute to ensure it is unique on a page. So you don't have actual knowledge what it will be.

    The easiest way is to use the class attribute to mark the element of interest, so your selector would be .someclass instead of #someid

    But if you absolutely have to: use an XPages output element to send a piece of computed inline css where you use expression language to obtain the actual id. Browsers or libraries might cough on the : in the id, so your result requires lots of testing. VanillaJS should work.