XUL:Attribute:id
出典: MDC
- id
- 型: window 内で固有の要素 ID
- 要素を識別するために付与される固有の識別子。
getElementById()などの DOM 関数やスタイルシートで要素を参照するために使うことができる。
[編集] 例
<button id="foo" label="Click Me" oncommand="doSomething()"/>
<script>
function doSomething(){
var myButton = document.getElementById('foo');
myButton.setAttribute('label','The button was pressed');
}
</script>
上記の例のさらに抽象的な例は、以下のようになる。
<button id="foo" label="Click Me" oncommand="setWidgetLabel(this, 'I was pressed')"/>
<script>
function setWidgetLabel(idName, newCaption){
document.getElementById( idName.id ).setAttribute('label',newCaption)
}
</script>