jquery - How to use a javascript function inside class attribute of an element -


i want create dynamic 'li' elements , want assign classes 'li' element javascript function based on parameters in load of page mean want function run on 'li' elements assign function to.

something : in design

<li class="nav-item somefunction("param1","param2")"> </li> 

and 'somefunction' javascript function returns classes string

to make 'li' element follows in end : after rendering

<li class="nav-item cssclass1 cssclass2 cssclass3 cssclass4"> </li> 

not how asked it, here how jquery:

codepen: https://codepen.io/anon/pen/xejkvl

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <style> .red{   color:red;   font-size:25px; } </style> <script> window.onload = function() {          $( "#example" ).addclass("red");        }  </script> <li id="example">example</li> 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -