k well i found a great solution that i rigged to fit my own
situation ... i worked w/ the code a bit and changed it up some from
what i originally posted.

here's the link to the article i found 
http://www.sitepoint.com/forums/showthread.php?t=554851

the jquery:

$('.showhide').click(function() {
    $('.clients').slideToggle(400);
    $(this).text($(this).text() == 'Show box' ? 'Hide box' : 'Show
box');
    return false;
});


html:

<div class="showhide">Show box</div>
<ul class="clients">
<li><img src="images/1.jpg" alt="photo1"/></li>
<li><img src="images/2.jpg" alt="photo2"/></li>
<li><img src="images/3.jpg" alt="photo3"/></li>
<li><img src="images/4.jpg" alt="photo4"/></li>
<li><img src="images/5.jpg" alt="photo5"/></li>
        <noscript>This is the description for the logo</noscript>
<!--close clients-->
</ul>


this time "showhide" doesn't wrap around "clients"



could someone explain what this line does:

    $(this).text($(this).text() == 'Show box' ? 'Hide box' : 'Show
box');

i don't like to have solutions unless i can understand the answer.
it'll help me learn better.



On Jun 19, 3:55 pm, Matt Kruse <m...@thekrusefamily.com> wrote:
> On Jun 19, 9:02 am, mojoeJohn <mojoej...@gmail.com> wrote:
>
> > obviously, i want thetexttotogglethe words "show" and "hide" in
> > accordance to the slidetoggle.
>
> I keep this in my toolbox:
>
> //Toggletextwithin an element using regular expressions.
> // Useful for changing "show" to "hide" and back when toggling element
> displays, for example
> jQuery.fn.toggleText = function(a,b) {
>         return this.html(this.html().replace(new RegExp("("+a+"|"+b
> +")"),function(x){return(x==a)?b:a;}));
>
> }
>
> Example:
>
> $('#mydiv').toggleText('show','hide');
>
> You can pass in regextext, and it cantoggletextwithin a string
> like:
>
> "Click here to show all items"
>
> and it will justtogglethe word "show" to "hide".
>
> Hope it's useful.
>
> Matt Kruse

Reply via email to