คัดลอกรหัสรหัสดังต่อไปนี้:
var getstyle = function(elementID,แอตทริบิวต์){
obj = document.getElementById(elementID);
//ด้านหน้าเป็น IE และด้านหลังเป็นมาตรฐานของ html
กลับ obj.currentStyle ? obj.currentStyle[แอตทริบิวต์] : document.defaultView.getComputedStyle(obj, false)[attribute];
-
นอกจากนี้ยังมีวิธีรับแอตทริบิวต์ style ที่เขียนด้วย html
คัดลอกรหัสรหัสดังต่อไปนี้:
document.getElementById("elementId").style.paddingLeft;