0

I'm currently writing a small html templating library, and it would make my life easier if I could wrap some dynamically generated html content with some meaningless html element that will only serve as an ID-holder. I've obviously thought of using a div, but the problem is that this would create some potential weirdness if it gets auto-generated into an inline element such as a span. Conversely, I don't want to use a span if the content of the span is some block element(s).

So, is there an html element I could use that has absolutely no style associated with it at all, such that I can use it purely as an ID-holder?

Thanks!

Fly
  • 810
  • 2
  • 9
  • 28
  • 1
    Why not just use `span`s or `div`s and alter their styiling to your liking? – opportunityr Dec 25 '18 at 17:14
  • 1
    @opportunityr Because at the time my code is generating the HTML it technically doesn't know what it's content are going to be / where it is going to be placed into, therefore I wouldn't know whether to block or inline -style it. I *could* with a lot of effort keep track of these two things, but then I might as well just build a system where I don't need an ID-holder at all. – Fly Dec 25 '18 at 17:17
  • 2
    Just make up your own element name, like ``. – yaakov Dec 25 '18 at 17:18
  • @YaakovAinspan And these won't have any styling associated with them, and yet still be grabbable through their ID tags & display their contents based on what the contents are? – Fly Dec 25 '18 at 17:21
  • Yep. That's how it works. – yaakov Dec 25 '18 at 17:22
  • @YaakovAinspan Awesome, I'll try that then. thanks! – Fly Dec 25 '18 at 17:24
  • I recommend that you also refer to this https://stackoverflow.com/questions/2802687/is-there-a-way-to-create-your-own-html-tag-in-html5 there’s some instruction on how to handle custom tags for older browsers. – Vaughn D. Taylor Dec 25 '18 at 17:31
  • 2
    Making up your own elements that don't contain dashes is STRONGLY DISCOURAGED. What if browsers implement an element with that name in the future? Then your website will starting behaving funky. Use a name with at least one dash, then you won't have that problem. Anyway, I wouldn't recommend doing it that way, since unknown elements are treated as having `display: inline`, so you'll have the same problems as with a span. And unknown elements are not always handled exactly the same way in different browsers, so beware of compatibility problems. – Mr Lister Dec 25 '18 at 18:34

1 Answers1

0

Just build your wrapper elements with a class that has it's display set to what you want:

<div id="unique" class="block_class">
   <div>some content</div>
</div>

in your CSS;

.block_class { display:block; }
Xavier
  • 109
  • 9