aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/htmltableelement/bgcolor/index.html
blob: 153b8eda49302b340dd5e078afa9dbf5fb677066 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
title: HTMLTableElement.bgColor
slug: Web/API/HTMLTableElement/bgColor
tags:
  - DOM
  - Gecko
translation_of: Web/API/HTMLTableElement/bgColor
---
<div>{{ ApiRef() }} {{ Deprecated_header() }}</div>

<h2 id="Summary" name="Summary">概要</h2>

<p><code>bgcolor</code> は、テーブルの背景色を取得 / 設定します。</p>

<h2 id="Syntax" name="Syntax">構文</h2>

<pre class="syntaxbox"><em>color</em> = table.bgColor
table.bgColor =<em>color</em></pre>

<h3 id="Parameters" name="Parameters">引数</h3>

<dl>
 <dt><em><code>color</code></em></dt>
 <dd>色を表す文字列</dd>
</dl>

<h2 id="Example" name="Example"></h2>

<pre class="brush:js">// テーブルの背景色をゴーストホワイトに設定

var t = document.getElementById('TableA'); // 対象テーブルへの参照を変数に代入
t.bgColor = 'ghostwhite'; // テーブルに背景色を設定

t.style.backgroundColor = 'ghostwhite'; // ※style 属性を設定する事によっても可能</pre>

<p><code>bgcolor</code> は DOM の <a href="/ja/docs/DOM/table.tBodies"><code>tbody</code></a><a href="/ja/docs/DOM/table.rows"><code>row</code></a><a href="/ja/docs/DOM/table.cells"><code>cell</code></a> オブジェクトに対して用いる事も可能です。</p>

<h2 id="Notes" name="Notes">注記</h2>

<p><code>bgcolor</code> 属性は、HTML 4.01 で非推奨属性に指定されています。 代替として CSS の {{cssxref("background-color")}} プロパティを用います。要素の <a href="/ja/docs/DOM/style#DOM_Style_Object"><code>style</code></a> 属性にこれを設定するか、或いはスタイルシートで設定します。</p>

<p>スタイルと文書情報の分離を図るのであれば、スタイルシート内に特定のクラス名でスタイルを予め定義しておき、JavaScript でテーブル要素にそのクラス名を設定するなどの方法を用いる方が良いでしょう。</p>

<pre class="brush:css">/* CSS */
.ghostwhiteBackground { background-color: ghostwhite; }</pre>

<pre class="brush:js">/* JS */
// ※変数 t にはテーブル要素への参照が代入済みであるとする

t.setAttribute("class", "ghostwhiteBackground");</pre>

<h2 id="Specification" name="Specification">仕様書</h2>

<ul>
 <li><a href="http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-83532985">DOM Level 2 HTML:<em>HTMLTableElement</em> .bgColor</a></li>
</ul>