The following sample code demonstrates how to access, list and modify attributes of the particular DOM element.


Element attributes cannot be used to modify element properties. The difference between attributes and properties is explained here:

using DotNetBrowser;
using DotNetBrowser.DOM;
using DotNetBrowser.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DOMGetAttributesSample
    class Program
        static void Main(string[] args)
            Browser browser = BrowserFactory.Create();
            browser.FinishLoadingFrameEvent += delegate (object sender, FinishLoadingEventArgs e)
                if (e.IsMainFrame)
                    //Get the document
                    DOMDocument document = e.Browser.GetDocument();
                    //Get the element by its Id
                    DOMElement link = document.GetElementById("link");

                    //Get the attributes of the received element
                    Dictionary<String, String> attributes = link.Attributes;

                    //Print attributes
                    foreach (var attribute in attributes)
                        Console.WriteLine(attribute.Key + " = " + attribute.Value);                        

                    //Update the style attribute value
                    link.SetAttribute("style", "background-color: blue;");
            browser.LoadHTML("<html><body><a href='#' id='link' title='Link title' style='background-color: red;'></a></body></html>");