jQuery Selector How to - Select all children elements and filter by class name








Question

We would like to know how to select all children elements and filter by class name.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.6.1.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--  w w w .j a v  a2s .  c  o m-->
    $("#parentdiv :not(.childdiv)").hide();
});
</script>
</head>
<body>
  <div id="parentdiv">
    <div class="childdiv">c1</div>
    <div class="childdiv">c2</div>
    <div style="display: inline">unformattedtext</div>
  </div>
</body>
</html>

The code above is rendered as follows: