[pmwiki-users] ID in wiki markups

Guillermo Calderon - INCO calderon at fing.edu.uy
Wed Mar 21 13:39:36 CDT 2007


Hans wrote:
> Tuesday, March 20, 2007, 11:06:43 PM, Guillermo wrote:
> 
> 
>>Why  would an author like to write ids in a wiki page?
>>(I think that  "class" is enought for more purposes)
> 
> 
> Most often ids are not necessary and classes may work fine.
> I use ids with the show/hide recipe, as it needs explicit ids for the
> divs a toggle button acts on. If you repeat the same id later on it
> will be ignored and the code fails, i.e. the toggle button does not
> work.

I am not sure that this behaviour was common to all browsers. In all 
cases, we have non-valid html and  the result is unpredictable.

  So if something fails it may give you an idea to check for
> duplicate ids. But generally only use them if they are absolutely
> needed, otherwise use classes.

One of this absolutely needed cases would be the use of 
javascript/dhtml in order to dynamically change some properties of 
some html elements.
In particular the function getElemntById requires an ID in order to 
obtain a reference to the element with this ID.
However, you have other ways to do the same without IDs:

   <script>
      function  doSomething(elem) {
	// change elem properties
         ....
      }
   </script>


   <elem1 onclick=doSomething(this.nextSibling) ><elem2 ... >


Then,  elem2 is changed when clicking on elem1.

Yes, this approach is more restrictive than using ID, but it works in
  many cases,  is more eficient and  is also cross browser.

(mmm ... perhaps, this is not the correct list for this message :( )




More information about the pmwiki-users mailing list