#240·htm

different attribute handling in div/span etc. and svg

Author: rozekCreated Feb 16, 2023Updated Jul 3, 2024

I am using "htm" with "preact" binding

When I'm using code like the following

render(html`
  <div  id=${false && 'id-1'} />
  <span id=${false && 'id-2'} />
  <svg  id=${false && 'id-3'}></svg>
  <svg  id=${true  && 'id-4'}></svg>
`, document.body)

"htm" handles the ids differently:

  • <div/> and <span/> get an id with the value "false" while
  • <svg/> elements behave as expected (the first one gets no id, the second one an id with the value id-4)

Is that the expected behaviour? I've also tested other attributes, always with the same result...