MArt,
With my recently developed use of arbitrary html tags for more sliders I
needed to make use of an ID, Which I pass to A macro to toggle the state
(via CSS). I have some possible approach's
- Let the author take control of the uniqueness, easy as below methods
- Use a functional prefix like m1 or more1
- Create a custom list in reverse order so it is easy to see the next
available, do this by searching for and possibly detecting reuse.
- Since the current tiddler is a unique key use it or a uniquid issued
on demand to prefix the id name with the current tiddler.
- Then with the the suffix you use you need only ensure uniqueness
within the tiddler and for the ID, and this is a logical necessity.
- Build a editor too bar to add content that requires a unique ID and
determine the next unique number as you do so.
- Also you can use a class on one or more tiddlers, and manipulating
their css will affect all tiddler with the same class, but that may not be
an issue.
By the way this only arises because html is designed effectively for a page
at a time, even a "whole document" at a time, yet tiddlywiki is a single
html "document" but our documents are tiddlers and we can have an unlimited
number of them at a time, on the screen at the same time.
I have not tested it but what happens when you use duplicate ID's?, nothing
if the tiddler is not open?
Your idea was deleted?
Tones
On Saturday, 3 July 2021 at 09:55:09 UTC+10 Mat wrote:
> Much appreciated Mario. What a great reply! (did you even create that
> example? Just for me???)
>
> So does the "ID issue" for "elements" only concern HTML elements then? I
> just posted an idea on gh:
> https://github.com/Jermolene/TiddlyWiki5/discussions/5844
>
> <:-)
>
>
> On Saturday, July 3, 2021 at 1:04:37 AM UTC+2 PMario wrote:
>
>> On Friday, July 2, 2021 at 6:56:58 PM UTC+2 Mat wrote:
>>
>>> In HTML one can apply an ID attribute to objects. I know this is not
>>> possible in TW... but I don't get why. Can someone explain why this is not
>>> possible or not appropriate, please.
>>
>>
>> Hi Mat,
>>
>> It is possible to use IDs with TW. ... BUT it won't be reliable. ...
>>
>> HTML element IDs are per definition unique. But with TW can't guarantee
>> this uniqueness since we have transclusions. So in the TW story-river it
>> can happen that an ID is visible 2 or more times.
>>
>> The CSS definitions will most likely work. BUT depending on the browser
>> implementation we can not guarantee a consistent behaviour for all
>> elements.
>>
>> Have a look at this jsFiddle: https://jsfiddle.net/fLcdq7ut/17/
>>
>> The HTML code is like this:
>>
>> <html>
>> <head>
>> <title>getElementById example</title>
>> </head>
>> <body>
>> <p id="para">Some ID text here</p>
>> <p class="para">Some classed text here</p>
>>
>> <button onclick="changeColor('blue');">blue</button>
>> <button onclick="changeColor('red');">red</button>
>>
>> <p id="para">Some ID text here</p>
>> <p class="para">Some classed text here</p></body>
>> </html>
>>
>> The JS code is like this:
>>
>> function changeColor(newColor) {
>> var elem = document.getElementById('para');
>> elem.style.color = newColor;
>>
>> var elements = document.getElementsByClassName('para');
>> for (var i=0; i<elements.length; i++) {
>> elements[i].style.color = newColor;
>> }
>> }
>>
>> If you click the buttons you see, that the ID elements are not updated
>> both. It's only the first one, since the function
>> document.getElementById() assumes there is only 1 of them. ... By
>> definition it will return the first element it finds in the DOM tree.
>>
>> document.getElementsByClassName() knows there can be many elements with
>> the same class name and it will return an array, so we can use a loop to
>> define the new color.
>>
>> This is only a fast example, to show the differences in a way that should
>> be understandable. .. It would be possible to add a class to the IDs too,
>> to get them with the class name. ... BUT this would only solve this
>> particular usecase.
>>
>> The browser assumes there is only 1 ID active at a time. So we just don't
>> know, what happens internally. We can't reliably guarantee that everything
>> works as expected.
>>
>> hope that helps
>> mario
>>
>
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/994fd3fe-3a15-46b0-99c6-c679523b485bn%40googlegroups.com.