space in tiddler name makes for a bad element id

24 views
Skip to first unread message

RA

unread,
Apr 22, 2009, 1:32:45 PM4/22/09
to TiddlyWiki
Turns out this is old news: http://bit.ly/QLnRc
So how do I go about finding the element in this case, when [[tiddler
name has spaces]]? This doesn't work:

var target = jQuery('#'+here.id+' .'+targetClass)[0];

Would a core tweak be appropriate? Say, to replace spaces with
underscores and underscores to two underscores when generating element
ids?

I cannot find the place in core source code where this is happening,
can anybody point it out to me?

Thanks.

-- R

FND

unread,
Apr 22, 2009, 2:23:55 PM4/22/09
to Tiddl...@googlegroups.com
> So how do I go about finding the element in this case, when [[tiddler
> name has spaces]]?

See this ticket:
http://trac.tiddlywiki.org/ticket/472

The thread linked from there has some details and a workaround,
documented on the community wiki:
http://tiddlywiki.org/wiki/Tiddler-Specific_Styles#Using_Tiddler_IDs


-- F.

RA

unread,
Apr 22, 2009, 2:52:42 PM4/22/09
to TiddlyWiki
The workaround is for use in CSS code, it doesn't explain what to do
if I need to pass the id as a string to another function that is not
built to handle spaces.
Tried to stick the octal code but it's just the same, doesn't work:

var target = jQuery('#'+here.id.replace(/ /g,'\040')+' .'+targetClass)
[0];


-- R

Eric Shulman

unread,
Apr 22, 2009, 3:27:00 PM4/22/09
to TiddlyWiki
var target=jQuery('#'+here.id.replace(/ /g,'\040')+' .'+targetClass)
[0];

Apparently, jQuery() can't handle the spaces. But
document.getElementById() does! Thus, you could write

var target=document.getElementById(here.id);

Of course, by definition, this will result in target == here... and
since you already have the value of 'here', you don't even need to do
the above line to get the desired element. In addition, because you
are really trying to retrieve an element contained within 'here' that
has a given classname, you can actually just write the following:

var target=here.getElementsByClassName(targetClass)[0];

enjoy,
-e

RA

unread,
Apr 22, 2009, 4:30:40 PM4/22/09
to TiddlyWiki
Yes, that was my point - jQuery gets straight to the target, using id
of the parent + className of it's child. Brilliant!

Back in TW realm, Eric saves the day yet again. Looks like the bug
needs to be sorted out before jQuery use kicks in for real.

-- R.
Reply all
Reply to author
Forward
0 new messages