I'm new at jQuery (just picked up a book this morning!) and I'm trying to hide an element; it doesn't seem to be working.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="javascript/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
if ($) {
$(document).ready(
function() {
$('ul li span').click(
function() {
$(this).parent().children('ul').hide();
}
);
}
);
}
</script>
</head>
<body>
<ul>
<li><a href="">My Controls <span class="arrow">↑</span></a>
<ul>
<li><a href="">My Profile</a></li>
</ul>
</li>
</ul>
</body>
</html>
This is the full code I'm using. When I click the span tag I want it to hide the inner <ul>
. I assumed that this
would access the span
element, parent()
the li
, and children()
the ul
contained instead the li
, but this doesn't seem to be the case. Am I making some sort of stupid mistake here?
TIA.