Lots of ways to make this more terse. For example, for the first
group,
$("#scaleButton").click(function(){
$('#resizerDiv, #infoDiv').filter(':visible').fadeToggle(100) ;
});
Are these objects adjacent in the same parent container? If so then
checkout .siblings().
THAT SAID, I sense a fault of logic here. fadeToggle() does a fadeIn
() if the object is invisible, and fadeOut() of it is visible. So
your code makes no sense. You probably should call fadeOut()
directly.
So the first group becomes, simply
$("#scaleButton").click(function(){
$('#resizerDiv, #infoDiv').fadeOut(100) ;
});
Or perhaps ultimately (depending on your situation, I'm guessing)
$("#scaleButton").click(function(){
$(this).siblings("div").fadeOut(100) ;
});
**--** Steve
**--** Steve
On Dec 3, 7:51 pm, Kory <[email protected]> wrote:
> Hi All,
>
> Im trying to build a menu system and each button I add Im having to
> add more and more code eg:
>
> $("#scaleButton").click(function(){
> $("#scaleDiv").fadeToggle(200) ;
> if($('#infoDiv').is(':visible')){
> $("#infoDiv").fadeToggle(100) ;
> }
> if($('#saveDiv').is(':visible')){
> $("#saveDiv").fadeToggle(100) ;
> }
> });
> $("#infoButton").click(function(){
> $("#infoDiv").fadeToggle(200) ;
> if($('#resizerDiv').is(':visible')){
> $("#resizerDiv").fadeToggle(100) ;
> }
> if($('#saveDiv').is(':visible')){
> $("#saveDiv").fadeToggle(100);
> }
> });
> $("#saveButton").click(function(){
> $("#saveDiv").fadeToggle(200) ;
> if($('#resizerDiv').is(':visible')){
> $("#resizerDiv").fadeToggle(100) ;
> }
> if($('#infoDiv').is(':visible')){
> $("#infoDiv").fadeToggle(100) ;
> }
> });
>
> //
>
> jQuery.fn.fadeToggle = function(speed, easing, callback) {
> return this.animate({opacity: 'toggle'}, speed, easing, callback);
>
> };
>
> so basically I have three buttons that open a div and hide the other
> two, how can I put this in a loop so I dont have to keep adding if
> statements?
>
> Thanks
--
You received this message because you are subscribed to the Google Groups
"jQuery UI" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jquery-ui?hl=en.