Friday 15 May 2015

javascript - How to mention all attributes in single line -



javascript - How to mention all attributes in single line -

how mention attributes in single line :)

document.getelementbyid("image").src = "landscape.jpg"; document.getelementbyid("image").width = "300"; document.getelementbyid("image").height = "300";

you can save variable white element, don't have document.getelementbyid each time

var img = document.getelementbyid("image"); img.src = "landscape.jpg"; img.width = img.height = "300";

you create function able in 1 line later

function setvalues(element, props){ for(var key in props){ element[key] = props[key]; } } setvalues(document.getelementbyid("image"), {src: "landscape.jpg", width:"300", height:"300"});

if need lot of dom manipulation, @ framework jquery , zepto, becomes overkill, if thing need change.

javascript attributes

No comments:

Post a Comment