views:

45

answers:

1

In the example below, I'm trying to figure out how to hide the fieldset if the text within the tags = Groups

<fieldset class=" collapsible">
<legend class="collapse-processed"><a href="#">Groups</a></legend>

I tried this, but, it winds up hiding all the fieldsets, not just this one...

$(this).find('legend').each( function() {
    if($(this).text('Groups')) {
        $(this).parent().hide();
    }
});
+4  A: 

Here's your problem:

if ($(this).text('Groups'))

This just changes the text of every legend to be "Groups". And returns a jQuery object (which will evaluate to true). You probably want something like,

if ( $(this).text() == 'Groups' )
  $(this).parent().hide();

If you can guarantee that the legends you wish to hide are the only ones containing the word "Groups", then you could simplify this further:

$("fieldset:has(legend:contains('Groups'))").hide();

...which will select only those fieldsets containing a legend element that in turn contains the character sequence "Groups".

Shog9
Ahh... Thank you. Still learning syntax, so I really appreciate it.
phpN00b