HtmlElement.TagName Propiedad

Definición

Obtiene el nombre de la etiqueta HTML.

public:
 property System::String ^ TagName { System::String ^ get(); };
public string TagName { get; }
member this.TagName : string
Public ReadOnly Property TagName As String

Valor de propiedad

Nombre que se usa para crear este elemento mediante marcado HTML.

Ejemplos

En el ejemplo de código siguiente se encuentran todas las IMG etiquetas de un documento y se usa la TagName propiedad para probar si IMG el elemento está enlazado a otra página; si es así, el código asigna la dirección URL al ALT atributo de la IMG etiqueta, de modo que los usuarios puedan pasar el mouse sobre la imagen para ver dónde los tomará.

private void AddUrlToTooltip()
{
    if (webBrowser1.Document != null)
    {
        foreach (HtmlElement elem in webBrowser1.Document.GetElementsByTagName("IMG"))
        {
            if (elem.Parent.TagName.Equals("A"))
            {
                String altStr = elem.GetAttribute("ALT");
                if (!(altStr == null) && (altStr.Length != 0))
                {
                    elem.SetAttribute("ALT", altStr + " - points to " + elem.Parent.GetAttribute("HREF"));
                }
                else
                {
                    elem.SetAttribute("ALT", "Points to " + elem.Parent.GetAttribute("HREF"));
                }
            }
        }
    }
}
Private Sub AddUrlToTooltip()
    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            For Each Elem As HtmlElement In .GetElementsByTagName("IMG")
                If (Elem.Parent.TagName.Equals("A")) Then
                    Dim AltStr As String = Elem.GetAttribute("ALT")
                    If (Not (AltStr Is Nothing) And (AltStr.Length <> 0)) Then
                        Elem.SetAttribute("ALT", AltStr & " - points to " & Elem.Parent.GetAttribute("HREF"))
                    Else
                        Elem.SetAttribute("ALT", "Points to " & Elem.Parent.GetAttribute("HREF"))
                    End If
                End If
            Next
        End With
    End If
End Sub

Comentarios

Muchos elementos del Modelo de objetos de documento HTML tienen atributos, propiedades y métodos que son únicos para esos elementos; por ejemplo, el HREF atributo en el A elemento o el Submit método en FORM. Use TagName cuando tenga un elemento de un tipo potencialmente arbitrario y tenga que realizar una operación específica del tipo.

Se aplica a

Consulte también