views:

12

answers:

1

Hi there,

New to this, so sorry if it's really silly. My problem is as follows. We have been given a list of anchors, some are html and some are pdf. These are grouped into a div #anchors which is to be hidden on document ready. Then two buttons with a choice to show either html links only or pdf links only and the href$ selector must be used. I can't get anything to show. Code as follows:

$(document).ready(function(){
    alert("Anchors hidden");
    $('#anchors').hide();
});

$(document).ready(function(){
  $('#htmlLinks').click(function(event){
    alert("html pressed");
    $("a[href$=html]").show();
  });
});

The alert shows, but none of the links are listed. I've tried loads of things. What am I doing wrong? I've tried $('#anchor a[href$=".html"]').show(); and various other things with different combinations of quotation marks, I've tried creating a new div and outputting to that, but I'm getting nowhere. I can get the whole div to display, but not a selection of it. Any help would be much appreciated.

Many Thanks.

A: 

You're hiding the whole div here:

$('#anchors').hide();

Instead, hide the anchors inside...the ones you want to show, like this:

$('#anchors a').hide();

If you .show() a child that still in a hidden parent you'll get no effect, which is what you're seeing. Instead do a .show() on the hidden element directly, and leave the parent visible.

Nick Craver
That's the conclusion I came to as well, but (and I think I got this right) the [demo I was putting together](http://jsbin.com/aheno3/2/) didn't seem to bear that out. Or have I just made a huge rookie mistake in there?
David Thomas
Nick, you are a superstar! I've been banging my head against this for hours. I could bloomin' well kiss you. :D
tilldawg
@David - Your selectors are off for your click handlers, they're classes where you have IDs, here's the updated version: http://jsbin.com/aheno3/3/edit
Nick Craver
@Nick, huge *and* embarrassing mistake...sigh. Thanks, I was staring at that for five minutes thinking 'whuh?' =)
David Thomas
@David - I like that people think others don't do the same thing at least 5 times a day....we all do, I'm up to twice today so far :)
Nick Craver