Compartir vía


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

String

Nombre utilizado para crear este elemento mediante código HTML.

Ejemplos

En el ejemplo de código siguiente se buscan todas las IMG etiquetas de un documento y se usa la TagName propiedad para comprobar si IMG se realiza un hipervínculo 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 llevará.

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; como el HREF atributo del 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