Span element does not start jQuery animation

I'm trying to make the menu on the right hand side with jQuery animation by clicking on a span that has a runmenu class, but it doesn’t work, I made the same class for button and it worked fine, what is the problem and why does it work only for button ?!

 $(document).ready(function() { $(".runmenu").click(function() { $(".menu").animate({ "right": 0 }, 1000); }); }); 
 /* Global*/ .conatianer { width: 1026.66px; } /*End global*/ /*Start navbar*/ .navbar { position: relative; background: url(http://vividmarketinginc.com/wp-content/uploads/2015/08/1672___selected7.jpg); background-size: cover; height: 700.531px; overflow: hidden; } .navbar .menu { position: absolute; right: -200px; width: 200px; height: 700px; background-color: gray; color: white; } .navbar .overlay { position: absolute; background-color: rgba(0, 0, 0, .2); width: 100%; height: 700.531px; z-index: 1; } .navbar .navbar_one, .navbar .navbar_two { position: relative; z-index: 2; } .navbar .navbar_one h3 { float: left; margin-top: 0; color: #FFF; padding: 20px; text-transform: capitalize; } .navbar .navbar_one div { float: right; margin-right: 10px; color: #FFF; padding: 20px; } .navbar .navbar_two { text-align: center; padding-top: 230px; } .navbar .navbar_two i { color: #FFF } .navbar .navbar_two h1 { text-transform: capitalize; color: #FFF; } .navbar .navbar_two h3 { text-transform: capitalize; color: #FFF } .navbar .navbar_two ul { list-style: none; } .navbar .navbar_two ul li { width: 110px; background-color: rgba(81, 186, 164, .8); -webkit-border-radius: 25px; -moz-border-radius: 10px; border-radius: 25px; text-align: center; color: #FFF; font-family: Arial; font-size: 20px; font-weight: 600; line-height: 10px; cursor: pointer; padding: 20px 25px; margin-left: 555px; } .navbar .navbar_two ul li:hover { background-color: #51baa4; } .navbar .navbar_two ul li a { color: #FFF; text-decoration: none } /*End navbar*/ 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <!DOCTYPE html> <html lang="en"> <head> <title>Template retrospect</title> <meta charset="utf-8" /> <link rel="stylesheet" href="css/StyleSheet.css" /> <link rel="stylesheet" href="css/font-awesome.min.css" /> <link rel="stylesheet" href="css/normalize.css" /> </head> <body> <!--Start NavBar--> <div class="navbar"> <div class="menu"> <!--Menu --> <i class="fa fa-long-arrow-right"></i> <ul> <li>home</li> <li>generic</li> <li>elements</li> </ul> </div> <div class="overlay"></div> <div class="navbar_one"> <h3>retrospect</h3> <div> <i class="fa fa-bars fa-lg"></i> <span class="runmenu">menu</span> </div> </div> <div class="navbar_two"> <i class="fa fa-soundcloud fa-4x"></i> <h1>etiam adipiscing</h1> <h3>magna feugiat lorem dolor egetas</h3> <ul> <li><a href="#" class="runmenu">learn more </a> </li> </ul> </div> </div> <script src="js/jquery-1.11.3.min.js"></script> <script src="js/JavaScript.js"></script> </body> </html> 
+6
source share
2 answers

All about z-index properties and nothing wrong with your javascript. Your span.runmenu not span.runmenu because the navbar2 block was placed above the span . Change css and fix the problem.

give

 .runmenu { z-index: 999; cursor: pointer; } .navbar .navbar_two { z-index: 0; } 

See script

Preview

 $(document).ready(function() { $('span.runmenu').click(function() { console.log("ok"); $(".menu").animate({ "right": 0 }, 1000); }); }); 
 /* Global*/ .runmenu { z-index: 999; cursor: pointer; } .conatianer { width: 1026.66px; } /*End global*/ /*Start navbar*/ .navbar { position: relative; background: url(http://vividmarketinginc.com/wp-content/uploads/2015/08/1672___selected7.jpg); background-size: cover; height: 700.531px; overflow: hidden; } .navbar .menu { position: absolute; right: -200px; width: 200px; height: 700px; background-color: gray; color: white; } .navbar .overlay { position: absolute; background-color: rgba(0, 0, 0, .2); width: 100%; height: 700.531px; z-index: 1; } .navbar .navbar_one, .navbar .navbar_two { position: relative; z-index: 2; } .navbar .navbar_one h3 { float: left; margin-top: 0; color: #FFF; padding: 20px; text-transform: capitalize; } .navbar .navbar_one div { float: right; margin-right: 10px; color: #FFF; padding: 20px; } .navbar .navbar_two { text-align: center; padding-top: 230px; z-index: 0; } .navbar .navbar_two i { color: #FFF } .navbar .navbar_two h1 { text-transform: capitalize; color: #FFF; } .navbar .navbar_two h3 { text-transform: capitalize; color: #FFF } .navbar .navbar_two ul { list-style: none; } .navbar .navbar_two ul li { width: 110px; background-color: rgba(81, 186, 164, .8); -webkit-border-radius: 25px; -moz-border-radius: 10px; border-radius: 25px; text-align: center; color: #FFF; font-family: Arial; font-size: 20px; font-weight: 600; line-height: 10px; cursor: pointer; padding: 20px 25px; margin-left: 555px; } .navbar .navbar_two ul li:hover { background-color: #51baa4; } .navbar .navbar_two ul li a { color: #FFF; text-decoration: none } /*End navbar*/ 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <body> <!--Start NavBar--> <div class="navbar"> <div class="menu"> <!--Menu --> <i class="fa fa-long-arrow-right"></i> <ul> <li>home</li> <li>generic</li> <li>elements</li> </ul> </div> <div class="overlay"></div> <div class="navbar_one"> <h3>retrospect</h3> <div> <i class="fa fa-bars fa-lg"></i> <span class="runmenu">menu</span> </div> </div> <div class="navbar_two"> <i class="fa fa-soundcloud fa-4x"></i> <h1>etiam adipiscing</h1> <h3>magna feugiat lorem dolor egetas</h3> <ul> <li><a href="#" class="runmenu">learn more </a> </li> </ul> </div> 
+6
source

I did the same a few months ago, the best way is to insert a span inside the div and encourage the div.

  $(".animamenu").click(function () { $(".animamenu").animate({ "right": 0 }, 1000); }); 

HTML:

 <div> <i class="fa fa-bars fa-lg"></i> <div class="animamenu"> <span class="runmenu">menu</span> </div> </div> 
-1
source

All Articles