Thursday, 15 August 2013

css - jQuery addclass and toggle class not setting my class -



css - jQuery addclass and toggle class not setting my class -

good day

for reason browser ignoring addclass , toggleclass jquery calls:

html <div id="menunav" class="row-fluid"> <div id="menunavsub" class="span12"> <ul> <li id="homenav"><a href="index.aspx"><img src="images/homenav2.png" /></a></li> <li id="gallerynav"><a href="galleries.aspx" class="block"><img src="images/homenav2.png" /></a></li> <li id="aboutnav"><a href="about.aspx"><img src="images/homenav2.png" /></a></li> <li id="contactnav"><a href="contact.aspx"><img src="images/homenav2.png" /></a></li> </ul> </div> </div> css: .activenavhome1 { background-position: -200px center; } .activenavhome2{ background: url('/images/homenavsmall.png') no-repeat left center; background-position: -150px center; } jquery: $('#homenav').addclass('activenavhome1'); if ($(window).width() < 1080) { $('#homenav').toggleclass('activenavhome2'); }

notes: using asp.net , jquery code contained in index.aspx file. html contained in master file.

however, when utilize

$('#homenav').css('background-position', '-200px center')

it works. why not assigning classes addclass , toggleclass commands? have made no spelling mistakes in css.

pass 2 classes instead , i think didn't referenced jquery library or may doc ready missing:

<script> $(function(){ // <-----------------------------you missing $('#homenav').addclass('activenavhome1'); if ($(window).width() < 1080) { $('#homenav').toggleclass('activenavhome1 activenavhome2'); } }); </script> note:

make sure have loaded jquery before script:

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

jquery css

No comments:

Post a Comment