Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
90
JavaScript "Set CSS" method for a node?
posted

I notice that there's a "get" for a node's main CSS class but I can't seem to find a "set". Is there a built-in way to manipulate this? I've done the following for the moment.

function setNodeCssClass(node, cssClass)
{
    var currentClass = node.get_cssClass();
    if (currentClass != cssClass)
    {
        //This method sets an internal object value but it doesn't affect the
        //actual HTML element.
        node._set_value($IG.DataTreeNodeProps.CssClass, cssClass);

        //We need to manipulate the anchor element's CSS class.
        var anchor = node.get_anchorElement();

        if (currentClass != "")
        {
            //Replace the current class.
            var regex = new RegExp("(^|\s)" + currentClass + "(?!\S)", "g");
            anchor.className = anchor.className.replace(regex, cssClass);
        }
        else
        {
            //Just add the new one.
            anchor.className += " " + cssClass;
        }
    }
}

Parents Reply Children
No Data