Dauguma šių funkcijų tinka ne tik div’am.
Norėdami dirbti su divu, turite jam priskirti id

  1. gražina į kintamajį elementą. Ją naudosiu tolesnėse funkcijose
  2. function getelement(element) {
  3. return document.getElementById(element);
  4. }
  5. //parodomo diva (veiks jeigu paslepimui naudojote stiliu: "display:none";
  6. function showdiv(name) {
  7. div=getelement(name);
  8. div.style.display=‘block’;
  9. return true;
  10. }
  11. //paslepia diva
  12. function hidediv(name) {
  13. div=getelement(name);
  14. div.style.display=‘none’;
  15. return true;
  16. }
  17. //keičia div rodymo/paslėpimo buseną. Tarkim paslėptą divą parodys, o matomą, paslėps.
  18. function swap_content(name){
  19. displayType=(document.getElementById(name).style.display==‘none’) ? ‘block’:‘none’;
  20. document.getElementById(name).style.display=displayType;
  21. return true;
  22. }
  23. //pakeičiam div’o turinį
  24. function writetodiv(div,text) {
  25. document.getElementById(div).innerHTML=text;
  26. return true;
  27. };
  28. //Diva nusiunčiam į centrą. Būtinai reikės funkcijų gauti lango dydžiui: <a href="http://blog.neworldwar.com/?p=42">jas rasite čia</a>
  29. function setContent(content) {
  30.         if (document.getElementById) {
  31.                 var windowHeight = getWindowHeight();
  32.                 var windowWidth = getWindowWidth();
  33.                 if (windowHeight > 0) {
  34.                         var contentElement = document.getElementById(content);
  35.                         var contentHeight = contentElement.offsetHeight;
  36.                         var contentWidth = contentElement.offsetWidth;
  37.                         if (windowHeight - contentHeight > 0) {
  38.                                 contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + ‘px’;
  39.                                 contentElement.style.left = ((windowWidth / 2) - (contentWidth / 2)) + ‘px’;
  40.                         }
  41.                 }
  42.         }
  43.         return false;
  44. }