[Javascript] syntax

Anthony Ettinger anthony at chovy.com
Fri Oct 12 11:39:32 CDT 2007


On 10/12/07, Dave Goodchild <buddhamagnet at gmail.com> wrote:
> Any lose the inline styles - why not apply classes instead?
>
>

Absolutely -- whenever I find myself escaping stuff with "\" its time
for me to rethink what I'm doing.

//css
.hide { display: none; }
.show { display: block; }
.visible { visibility: visible; }
.testL { left:10%; width: 200px; position:absolute; font-size:20px; }

<!-- html -->
<div onmousedown="do_something();">
</div>

//javascript
function do_something() {
   var testElement = document.getElementById('TestL');
   var insertThisElement = document.createChild('div');

   insertThisElement.className = 'testL';
   testElement.className = 'visible';
   testElement.appendChild(insertThisElement);


  ///etc, etc.
}


At the very least, use double quotes for your markup with innerHTML,
and surround it with single quotes (you will avoid having to escape
single quotes.

document.getElementById ('TestL').style.visibility='visible'
; document.getElementById('TestL').innerHTML='<div style=\'\'>Test</div><div
style=\'top:35px; left:1%; position: absolute;\'><img
src=\'test1.jpg\'></div><div style=\'right:18%; top: 0px; right:60px;
width: 100px; position:absolute; font-size:20px;\'>Test</div><div
style=\'right:1%; position: absolute; top:35px;\'><img src=\' test2.jpg\'
width=\'300px\'></div><div style=\'right:1%; top: 260px; width: 220px;
position:absolute; font-size:20px;\'>Test</div><div style=\'right:2%;
top:298px; position: absolute;\'><img src=\' test3.jpg\'
width=\'200px\'></div><div style=\'left:360px; top:40px; position:
absolute;\' align=\'left\'><u>Text</u><br /><br /><ul><li>text1</li>
<li>text2</li> </div><div style=\'top:370px; width 60px;  left: 45%;
position: absolute;\'><a href=\'\'
onmousedown=\'document.getElementById(\'TestL\').style.visibility=\'hidd
en\'\'><center>Close</a></center></div> '"


-- 
Anthony Ettinger
Ph: 408-656-2473
var (bonita, farley) = new Dog;
farley.barks("very loud");
bonita.barks("at strangers");

http://chovy.dyndns.org/resume/
http://utuxia.com/consulting



More information about the Javascript mailing list