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
No Data
Reply
  • 25665
    Offline posted

    Hello Vector,

    Thank you for contacting Infragistics!

    I have some follow up questions:

    What are the styles you want to set?
    Are these styles going to change or are they something you only want to set once when the app/site starts?
    Are all the nodes going to have the same styles or are different nodes going to have different styles?

Children