Search code examples
javascripthtmlmaterialize

Change color of collapsible on click materialize


I would like to change the color of the collapsible header only when I click on it.

<div class="collapsible-header" onclick="connect()"></div>

I have to add the color inside the class element, and I do not really know how to add something to it when I call the "connect" funtion. Is this possible ?

Thank you !

Tried with the following but is not working

HTML

<div class="collapsible-header" onclick="connect(this)">Robot</div> 

And in JS

function connect(element) 
{ 
    element.style.color = 'red';
    if (connection_status == 0)
    { 
        client.connect(options);
    };
}

Solution

  • https://jsbin.com/sojefubudo/edit?html,js,console,output

    <div class="collapsible-header" onclick="connect(this)"></div>
    

    And in javascript :

    function connect(element) {
      element.style.color = 'red';
    }