The listStyle
property sets or gets
the shorthand form property for a list.
We can use this property to set the following three properties.
listStyle |
Yes | Yes | Yes | Yes | Yes |
Return the listStyle property:
var v = object.style.listStyle
Set the listStyle property:
object.style.listStyle='type position image|initial|inherit
Parameter | Description |
---|---|
type | Set the list-item marker type |
position | Position the list-item marker |
image | Set an image for the list-item marker |
initial | Set to default value. |
inherit | Inherit from its parent element. |
Default Value: | disc outside none |
---|---|
Return Value: | A string representing the list style |
CSS Version | CSS1 |
The following code shows how to change the list style.
<!DOCTYPE html>
<html>
<body>
<ul id="myList">
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
</ul><!-- w ww . j av a 2 s . c o m-->
<button type="button" onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myList").style.listStyle = "decimal inside";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the list style.
<!DOCTYPE html>
<html>
<body>
<ul id="myList" style="list-style:decimal-leading-zero inside;">
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
</ul><!-- w ww. j a v a2s . c o m-->
<button type="button" onclick="myFunction()">test</button>
<script>
function myFunction() {
console.log(document.getElementById("myList").style.listStyle);
}
</script>
</body>
</html>
The code above is rendered as follows: