You're right Aaron. The attribute selector was malformed. The other
problem is that the '.child' element is not the previous sibling of
the 'a[name=selected]' element, which is what the .prev() method is
looking for.
Keir, you need to go *up* the DOM. Also, not sure why you want to hide
that element only to immediately show it again. But anyway, you could
do it like this:
$('a[name=selected]').parent().parent().show();
or like this:
$('a[name=selected]').parents('ul.child').show();
--Karl
____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On Sep 9, 2008, at 1:00 PM, [EMAIL PROTECTED] wrote:
I think your attribute selector is malformed.
Try:
<script type="text/javascript">
$(document).ready(function() {
$('.child').hide();
$("a[name='selected']").prev('.child').show();
});
</script>
On Sep 9, 6:43 am, Keir <[EMAIL PROTECTED]> wrote:
Hi,
I'm sure to a whizz this is going to be a bit of a noob question, but
why doesn't my prev() work here:
<script type="text/javascript">
$(document).ready(function() {
$('.child').hide();
$('name=selected').prev('.child').show();
});
</script>
HTML:
<ul class="parent">
<li><a href="">test 1</a></li>
<li><a href="">test 1</a>
<ul class="child">
<li><a href="" name="selected">test 1</a></li>
<li><a href="">test 1</a></li>
</ul>
</li>
<li><a href="">test 1</a>
<ul class="child">
<li><a href="">test 1</a></li>
<li><a href="">test 1</a></li>
</ul>
</li>
</ul>
Cheers chaps,
Keir