jQuery HTML Element How to - Add LI item








Question

We would like to know how to add LI item.

Answer


<!--from   www  .  jav a  2  s  .  c  o  m-->
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<style type='text/css'>
#newLine .dog {
  color: #F00;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $('button').click(function(){
        $('#newLine').append("<li class='dog'>Dog</li>");
    });
});
</script>
</head>
<body>
  <UL id='newLine'></UL>
  <button>click</button>
</body>
</html>

The code above is rendered as follows: