0

How to relate to the following element in a .css file by its id :

<div class="wrapper" id="wrapper-Fruits & Vegetables">
</div>

Thanks in advance.

  • 1
    You don't. Because that's not a valid `id` value. – David Apr 22 '19 at 12:05
  • Any other possible ways to accomplish the scenario? –  Apr 22 '19 at 12:07
  • 1
    Sure. Use a valid `id`. As long as the markup is invalid then any code which operates on that markup is undefined. It might work, it might not. – David Apr 22 '19 at 12:10
  • Use another attribute. `data-id` would be good. Then use the attribute selector syntax in the CSS: `div[data-id='wrapper-Fruits & Vegetables']` – Mr Lister Apr 22 '19 at 12:20
  • Great hack @MrLister. Thanks. I'm advised by one of my seniors here on stackoverflow to avoid creating such scenarios where I might be needing to find hacks throughout. –  Apr 22 '19 at 12:24
  • That's absolutely not a `hack`, it's just a CSS selector. https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors – Quentin Veron Apr 22 '19 at 15:11
  • @QuentinVeron haha I know what you mean. That's correct. I'm glad to see there are alternatives (ways around) to platform restrictions and at the same I'm also convinced to avoid unnecessary ways around wherever possible. Thank you. –  Apr 23 '19 at 08:35

0 Answers0