Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <div class="parent">
    <a>Parent 1</a>
    <a class="child">child of parent 1 contents</a>
  </div>
  <div class="parent">
    <a>Parent 2</a>
    <a class="child">child of parent 2 contents</a>
 </div>
</body>
</html>
 
a {
  color: blue;
  cursor: pointer;
  display: block;
}
a:hover {
  color: green;
}
.parent > .child {
  display: none;
}
 
$('.parent').click(function() {
  var $child = $(this).children('.child');
  var cls = $child.attr('class');
  console.log(cls);
  $child.show(); //added so that you can click the child
});
$('.child').click(function() {
  var html = $(this).html();
  console.log(html);
  //if you just want the text, use this instead:
  var text = $(this).text();
  console.log(text);
});
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers