เมื่อเนื้อหา溢出 (overflow) ให้ใช้คุณสมบัติ overflowX เพื่อจัดการขอบแนวนอน ตั้งค่าเป็น scroll จะแสดง scrollbar แนวนอนให้ผู้ใช้เลื่อนอ่านได้ ตัวอย่าง <!DOCTYPE html> <html> <head> <style> #box { width: 350px; height: 150px; background-color: o
เมื่อเนื้อหา溢出 (overflow) ให้ใช้คุณสมบัติ overflowX เพื่อจัดการขอบแนวนอน ตั้งค่าเป็น scroll จะแสดง scrollbar แนวนอนให้ผู้ใช้เลื่อนอ่านได้ ตัวอย่าง <!DOCTYPE html> <html> <head> <style> #box { width: 350px; height: 150px; background-color: o
เข้าถึงคุณสมบัติ buf.buffer โดยตรงเพื่อแปลง Buffer เป็น ArrayBuffer การเขียนผ่าน Buffer instance เดิมจะเขียนลง ArrayBufferView หมายเหตุ: ใน Node.js 4.x+ Buffer instances ก็เป็น Uint8Array instances ด้วย ตัวอย่างฟังก์ชันแปลง: function toArrayBuffer(myBuf) { var myBuffer = new ArrayBuffer(myBuf.leng
เบราว์เซอร์สมัยใหม่รองรับ SVG ทั้งหมด สามารถสร้าง SVG ด้วย JavaScript โดย: สร้าง SVG document object model (DOM) ว่างเปล่า ใช้ attributes สร้างรูปทรง เช่น วงกลม สี่เหลี่ยม var mySvg = https://www.w3.org/2000/svg; var myDoc = evt.target.ownerDocument; var myShape = svgDocument.createElementNS(mySvg
ใช้ Element.innerHTML หรือ textContent เพื่อแสดงค่าตัวแปรในหน้าเว็บ วิธีนี้ปลอดภัยและทันสมัยกว่า document.write ตัวอย่าง: var $myName = document.querySelector(.name); var $jsValue = document.querySelector(.jsValue); $myName.addEventListener(input, function(event){ $jsValue.innerHTML = $myName.valu
ใช้คุณสมบัติ maxHeight เพื่อจำกัดความสูงสูงสุดขององค์ประกอบ เนื้อหาที่เกินจะถูกตัดหรือแสดง scroll ตาม overflow ตัวอย่าง <!DOCTYPE html> <html> <head> <style> #box { width: 300px; background-color: gray; overflow: auto; } </styl
ใช้คุณสมบัติ shorthand margin เพื่อกำหนดขอบทั้ง 4 ด้านพร้อมกัน รูปแบบ: top right bottom left (ตามเข็มนาฬิกา) ตัวอย่าง <!DOCTYPE html> <html> <body> <button type=button onclick=display()>Set all four margins</button> <p id=myID>This is demo text.</p>
ใช้คุณสมบัติ listStyleType เพื่อเปลี่ยนรูปแบบเครื่องหมายรายการ เช่น disc, circle, square, decimal, lower-roman ฯลฯ ตัวอย่าง <!DOCTYPE html> <html> <body> <ul id=myID> <li>One</li> <li>Two</li> </ul> <button type=butto
ใช้คุณสมบัติ marginBottom เพื่อกำหนดระยะห่างจากขอบล่างขององค์ประกอบ ตัวอย่าง <!DOCTYPE html> <html> <body> <p id=myID>This is demo text.</p> <button type=button onclick=display()>Set bottom margin</button> <script> function display(
ใช้คุณสมบัติ marginTop เพื่อกำหนดระยะห่างจากขอบบนขององค์ประกอบ ตัวอย่าง <!DOCTYPE html> <html> <head> <style> #myID { border: 2px solid #000000; } </style> </head> <body> <div id=myID>This is demo text.</div>
ใช้คุณสมบัติ marginRight เพื่อกำหนดระยะห่างจากขอบขวาขององค์ประกอบ ตัวอย่าง <!DOCTYPE html> <html> <head> <style> #myID { border: 2px solid #000000; } </style> </head> <body> <div id=myID>This is demo text.</div&
ใช้คุณสมบัติ maxWidth เพื่อจำกัดความกว้างสูงสุดขององค์ประกอบ จะไม่ขยายกว้างกว่านี้แม้พื้นที่จะมาก ตัวอย่าง <!DOCTYPE html> <html> <body> <p>Click below to set Maximum width.</p> <button type=button onclick=display()>Max Width</button> <div i
ใช้คุณสมบัติ minHeight เพื่อกำหนดความสูงขั้นต่ำขององค์ประกอบ เนื้อหาจะไม่ยุบสั้นกว่านี้ (แต่สามารถขยายได้) ตัวอย่าง <!DOCTYPE html> <html> <head> <style> #box { width: 300px; background-color: gray; overflow: auto; } </style>
ใช้คุณสมบัติ minWidth เพื่อกำหนดความกว้างขั้นต่ำขององค์ประกอบ จะไม่ยุบเล็กลงกว่านี้แม้พื้นที่จะแคบ ตัวอย่าง <!DOCTYPE html> <html> <head> <style> #box { width: 50%; background-color: gray; } </style> </head> <body>
ใช้คุณสมบัติ opacity เพื่อกำหนดความโปร่งแสงขององค์ประกอบทั้งหมด (รวมลูก) ค่า 0 (โปร่งใส) ถึง 1 (ทึบแสง) หรือเปอร์เซ็นต์ ตัวอย่าง <!DOCTYPE html> <html> <head> <style> #box { width: 450px; background-color: gray; } </style> </he
ใช้คุณสมบัติ fontSizeAdjust เพื่อรักษาอัตราส่วนความสูงของตัวอักษรพิมพ์เล็ก (x-height) เมื่อฟอนต์สำรอง (fallback) ถูกใช้งาน ทำให้ข้อความอ่านง่ายต่อเนื่อง ตัวอย่าง <!DOCTYPE html> <html> <body> <h1>Heading 1</h1> <p id=myID>This is Demo Text.</p>
ใช้ Set และ filter เพื่อหาค่าที่ซ้ำกันระหว่าง 2 อาเรย์ วิธีนี้กระชับและมีประสิทธิภาพดี ตัวอย่าง y.has(k)); }; document.write(intersection([5,7,4,8], [3,9,8,4,3])); // แสดง 4,8 </script> </body> </html>
IE รุ่นเก่าไม่รองรับ addEventListener ใช้ attachEvent แทน วิธีแก้: 1. บังคับ IE ใช้โหมดใหม่ที่สุด: <meta http-equiv=X-UA-Compatible content=IE=edge; /> 2. ใช้ feature detection แบบ cross-browser: if (ev.addEventListener) { ev.addEventListener(click, myText, false); } else if (ev.attachEvent)
ใช้คุณสมบัติ letterSpacing เพื่อเพิ่มหรือลดระยะห่างระหว่างตัวอักษร ใช้หน่วยความยาว เช่น px, em ตัวอย่าง <!DOCTYPE html> <html> <body> <h1>Heading 1</h1> <p id=myID>This is Demo Text.</p> <button type=button onclick=display()>Set Space bet
ใช้คุณสมบัติ shorthand listStyle เพื่อกำหนดรูปภาพ ตำแหน่ง และประเภทเครื่องหมายรายการพร้อมกัน ตัวอย่าง <!DOCTYPE html> <html> <body> <ol id=myID> <li>One</li> <li>Two</li> </ol> <button type=button onclick=display()>
ใช้คุณสมบัติ lineHeight เพื่อกำหนดระยะห่างระหว่างบรรทัดของข้อความ สามารถใช้ตัวเลข (คูณกับ font-size), ความยาว (px, em), หรือเปอร์เซ็นต์ ตัวอย่าง <!DOCTYPE html> <html> <body> <h1>Heading 1</h1> <p id=myID>This is Demo Text.<br>This is Demo Text<