var bang = $('.bang').hide();
$('a.collapse').click(function(){
var vis = bang.is(':visible');
bang[ vis ? 'hide' : 'show' ]();
$(this).text( vis ? '(+)' : '(-)' );
});
On Nov 23, 5:18 pm, mdrisser <[EMAIL PROTECTED]> wrote:
> Jay,
> Your code works great, but adds a couple of extra steps. Its not
> necessary to empty the html first, if you call .html() with an
> argument containing what you want to appear there, jQuery will clear
> the exisiting html for you and then replace it with what you had
> desired.
>
> // Works, but adds an extra step
> $('#myID').html('').append('<p>Something I want to appear in myID</
> p>');
>
> // Does the same thing, but with less typing ;-)
> $('#myID').html('<p>Something I want to appear in myID</p>');
>
> Just a tip for those of us 'Lazy' Programmers ;-)
>
> On Nov 21, 11:16 am, Jay Fallon <[EMAIL PROTECTED]> wrote:
>
> > You need to clear your HTML first. remove() does nothing.
>
> > <script type="text/javascript">
> > $(document).ready(function(){
> > $('div.bang').addClass('hide');
> > $('a.collapse').toggle(function(){
> > $('div.bang').show();
> > $('a.collapse').html("").append("(-)");
> > }, function(){
> > $('div.bang').hide();
> > $('a.collapse').html("").append("(+)");
> > });});
>
> > </script>
>
> > On Nov 21, 1:35 pm, FrankTudor <[EMAIL PROTECTED]> wrote:
>
> > > <script type="text/javascript">
> > > $(document).ready(function(){
>
> > > $('.bang').hide();
>
> > > $("a.collapse").toggle(function()
> > > {
> > > $('.bang').show();
> > > $('a.collapse').remove("(-)").append("(+)");
>
> > > },function(){
>
> > > $('.bang').hide();
> > > $('a.collapse').remove("(+)").append("(-)");});
> > > });
>
> > > </script>
>
> > > <head>
> > > <body>
>
> > > <a href="" class="collapse">(-)</a>
>
> > > <div class="bang">
> > > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean at
> > > magna nec erat tincidunt sollicitudin. Phasellus eu est. Aenean diam
> > > elit, laoreet sed, suscipit eget, hendrerit vel, lorem. Suspendisse
> > > nec turpis ullamcorper urna accumsan sollicitudin.
> > > </div>
>
> > > Can someone put a set of eyes on the above code...It doesn't seem to
> > > work and I am not sure why.
>
> > > Thanks,
> > > Frank