Why using class and not id

1 view
Skip to first unread message

benoit

unread,
Mar 19, 2015, 5:48:09 PM3/19/15
to Iliad project
Hi all,

I was playing with widgets in Iliad, changing the default root element
to not having another div around my widget. Then I set the class for the
root element and *pouf* Iliad isn't working anymore.

After digging in the framework I understand that it's not a good idea
to mesh div used as widget container and other elements used for
document presentation.

But I wonder why is Iliad using the "class" attribute instead of the
"id" attribute to update the widget ?

Excerpt from iliad.js :
function updateWidget(id, contents) {
jQuery("."+id).replaceWith(contents);
}

It seems to me, more logical to use the id, but there should be some
reason I can't see.

function updateWidget(id, contents) {
jQuery("#"+id).replaceWith(contents);
}


Perplexed Benoit

nicolas petton

unread,
Mar 20, 2015, 5:11:47 AM3/20/15
to Iliad ML
> Hi all,

Hi,

>
>   I was playing with widgets in Iliad, changing the default root element 
> to not having another div around my widget. Then I set the class for the 
> root element and *pouf* Iliad isn't working anymore.
>
>   After digging in the framework I understand that it's not a good idea 
> to mesh div used as widget container and other elements used for 
> document presentation.

You can change the root element though. (There's a method for that in
ILWidget).

>
>   But I wonder why is Iliad using the "class" attribute instead of the 
> "id" attribute to update the widget ?

The reason is that the same widget might be rendered several times in
the same page. If we were using ids, it would not be possible.

HTH,
Nico



--
You received this message because you are subscribed to the Google Groups "Iliad project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iliad+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

benoit

unread,
Mar 23, 2015, 6:52:40 PM3/23/15
to il...@googlegroups.com
Le 3/20/15 10:11 AM, nicolas petton a écrit :
> > But I wonder why is Iliad using the "class" attribute instead of the
> > "id" attribute to update the widget ?
>
> The reason is that the same widget might be rendered several times in
> the same page. If we were using ids, it would not be possible.

Oh, it seems obvious now that you say it.

Well, what would be nice now that it's common to have multiple css
class on one html element would be to make Iliad more aware of it. To be
able to change the css class of a widget without breaking this mecanism.
I will look into it.


By the way I have added the caption element from a table to Iliad. You
can found the code on Smalltalk Hub :
http://smalltalkhub.com/#!/~BenoitAstruc/Iliad.

Benoit

Reply all
Reply to author
Forward
0 new messages