Skip to content Skip to sidebar Skip to footer

Assigning A Cssclass To Each Li Element In An Unordered List Programmatically

I've an unorderedlist something like this.
  • root
    • Tree Node 1&l

Solution 1:

JavaScript:

You could use the DOMObject.innerHTML read/write property. Or, jQuery's .append(). For the attributes, the DOMObject.setAttribute() should get you all the way.

Check out this piece of jQuery documentation and this.

Am I missing some functionality you wanted?

Solution 2:

you are doing the wrong thing.

instead of that approach, i would suggest a different one

  1. Generate the ul element with an id or class
  2. use that id or class in your style sheet

for e.g

<ul>    
  <li>    
  <span>root</span>
  <li>
</ul>

i would generate like

<ulclass='mylist'><li><span>root</span><li></ul>

my css would contain

ul.mylist {
 write your style properties 
}

ul.mylistli{
 write your style property for li element
}

Then your records will be displayed properly.

Post a Comment for "Assigning A Cssclass To Each Li Element In An Unordered List Programmatically"