HtmlElement.SetAttribute(String, String) メソッド

定義

要素の名前付き属性の値を設定します。

public:
 void SetAttribute(System::String ^ attributeName, System::String ^ value);
public void SetAttribute (string attributeName, string value);
member this.SetAttribute : string * string -> unit
Public Sub SetAttribute (attributeName As String, value As String)

パラメーター

attributeName
String

設定する属性名です。

value
String

この属性の新しい値。

次のコード例では、 を使用してSetAttributeイメージの属性を設定SRCして、現在のドキュメントに新しいIMG要素を追加します。

private void InsertImageFooter()
{
    if (webBrowser1.Document != null)
    {
        HtmlDocument doc = webBrowser1.Document;
        HtmlElement elem = doc.CreateElement("IMG");
        elem.SetAttribute("SRC", "http://www.adatum.com/images/footer-banner.jpg");

        doc.Body.AppendChild(elem);
    }
}
Private Sub InsertImageFooter()
    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            Dim Elem As HtmlElement = .CreateElement("IMG")
            Elem.SetAttribute("SRC", "http://www.adatum.com/images/footer-banner.jpg")

            .Body.AppendChild(Elem)
        End With
    End If
End Sub

注釈

HTML の属性は、その要素の有効な名前と値のペアです。 HtmlElement は、すべての要素に共通する属性のみを公開し、特定の種類の要素にのみ適用される属性を除外します。 SRC はタグの定義済み属性 IMG です。たとえば、 タグの DIV 属性ではありません。 および SetAttribute を使用してGetAttribute、マネージド ドキュメント オブジェクト モデル (DOM) で公開されていない属性を操作します。

が要素に対して定義された属性でない場合 attributeName は、 SetAttribute 要素に対して新しい属性として定義されます。

GetAttribute と では大文字と SetAttribute 小文字が区別されません。

HtmlElement属性をclass設定するには、最初の引数を に指定する場合と同じように className 属性を参照する必要があります。SetAttribute

適用対象

こちらもご覧ください