Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    kao
    kao is offline
    New Coder
    Join Date
    Jan 2010
    Posts
    18
    Thanks
    4
    Thanked 2 Times in 2 Posts

    Can't get the "else" part of a satement to work

    So i have a navigation area with tabs of to the side im changing their z-index
    so its pops out when hovered on. the first part works fine it pops out.

    but i cannot seam to figure out how to get it to revert back to its default level.
    Code:
          <script type="text/javascript">
          var value = parseInt($("#aa1").css("z-index"))
          var value2 = parseInt($("#aa1").css("z-index"))
    
          
          $("#aa1").hover(function() {
          if (value == value2) {
             $(this).css({'z-index' : (value + 22), 'font-weight' : 'bolder'});
            }
            
            else 
            { $(this).css({'z-index' : (value), 'font-weight' : 'normal'}) }
            });
          
          
          
          </script>
    the button titled What is the working example
    live example is here http://dev.f-k-n.net/dmtm/gnav.html


    Thanks for looking.
    Last edited by kao; 07-14-2011 at 09:44 PM.

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,957
    Thanks
    9
    Thanked 727 Times in 721 Posts
    jQuery hover() can take two arguments, which allows you to run a function on mouseenter and another on mouseleave . Assuming you want to revert on mouseout then try:

    Code:
          <script type="text/javascript">
          var value = parseInt($("#aa1").css("z-index"))
    
         $("#aa1").hover(function() {
                   $(this).css({'z-index' : (value + 22), 'font-weight' : 'bolder'});//function on mouseenter
          },function(){
    	       $(this).css({'z-index' : (value), 'font-weight' : 'normal'});//function on mouseleave
          });
          
          
           </script>

  • Users who have thanked SB65 for this post:

    kao (07-14-2011)

  • #3
    kao
    kao is offline
    New Coder
    Join Date
    Jan 2010
    Posts
    18
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Awesome thanks, SB65. That worked like a charm.

    Also, I am glad also that you told me that it supports 2 Arguments.
    I am new to learning jquery and still haven't reached the apex of its learning curve.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •