Thursday, December 6, 2012

style.background

Properti style.background adalah bentuk shorthand untuk mendeklarasikan style.backgroundColor, style.backgroundImage, style.backgroundRepeat, style.backgroundAttachment, dan style.backgroundPosition dalam satu deklarasi.

Sintaks:

obj.style.background = value;

Nilainya:

  • sub-style.background
    style.backgroundColor, style.backgroundImage, style.backgroundRepeat, style.backgroundAttachment, dan style.backgroundPosition yang dipisahkan spasi.
  • inherit.

Contoh 1:

<HTML> <HEAD> <TITLE>style.background</TITLE> </HEAD> <BODY> <SCRIPT TYPE="text/javascript"> var bodyElem = document.getElementsByTagName("body")[0]; bodyElem.style.background = "#FFF url(picture.gif) no-repeat center"; </SCRIPT> </BODY> </HTML>

Contoh 2:

<HTML> <HEAD> <TITLE>style.background</TITLE> <STYLE TYPE="text/css"> #mydiv { width: 200px; height: 200px; border: solid green 2px; } </STYLE> </HEAD> <BODY> <DIV ID="mydiv"></DIV> <SCRIPT TYPE="text/javascript"> var divElem = document.getElementById("mydiv"); divElem.style.background = "#FFF url(picture.gif) no-repeat center"; </SCRIPT> </BODY> </HTML>