Click event not registering with jQuery -


i have mvc 4 application basic template. in _layout.cshtml have code:

<script type="text/javascript">         $(window).load(function () {             $("body").on({                 // when ajaxstart fired, add 'loading' body class                 ajaxstart: function () {                     $(this).addclass("loading");                 },                 // when ajaxstop fired, remove 'loading' body class                 ajaxstop: function () {                     $(this).removeclass("loading");                 }             });              $("a").click(function () {                 $(this).addclass("loading");             });         });      </script> 

and html in same:

<body>     @renderbody()      @scripts.render("~/bundles/jquery")     @rendersection("scripts", required: false)     <div class="modal"></div> </body> 

i created homecontroller has code given mvc. in index view have this:

@{     viewbag.title = "index"; }  <h2>index</h2> <a href="#">some <span class="red">text</span></a> 

i trying understand on how implement loader whenever link or ajax request made across application.

got lot of here , here.

the above code not showing loader when link clicked, there aren't ajax calls of now. simple thing lot of jquery gurus out there having hard time understanding events hookup using jquery trying learn small baby steps.

can guide me on how show loader , hide it?

appreciate help. regards.

try this, if not created dyanmically, if created on runtime need bind while creation time.

<script type="text/javascript">     $(function () {         $("body").on({             // when ajaxstart fired, add 'loading' body class             ajaxstart: function () {                 $(this).addclass("loading");             },             // when ajaxstop fired, remove 'loading' body class             ajaxstop: function () {                 $(this).removeclass("loading");             }         });          $("a").click(function () {             $(this).addclass("loading");         });     });  </script> 

demo


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -