jQuery Selector How to - Select just added elements








Question

We would like to know how to select just added elements.

Answer


<!--from  w  ww.j av  a 2 s.  c o m-->
<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("div").html("<b>bold</b> not bold");
            $("div b").append(document.createTextNode("!!!")).css("color", "red");
        });
    </script>
  </head>
  <body>
      <DIV></DIV>
  </body>
</html>

The code above is rendered as follows: