javascript - Running a JQuery animation depending on which option is chosen -


i've searched lot , sure has needed before sorry if duplicate. took thought compilation of best code find online , coudln't work.

i know structure way off, know why wrong.

$(document).ready(function () {   $("select[name='selector']").change(function () {     $(this).children(':selected').hasclass('three') {       $("#mover").animate({         "left": "+=50px"       });     };   }); }); 

live example.

a couple of things:

  1. what need conditional if statement, that's basic of language.
  2. the left css attribute taken account when absolute positioning being used.

as code,

#mover {     position: absolute; } 

$(document).ready(function () {     var $selector = $("select[name='selector']"), $mover = $("#mover");     $selector.change(function () {         if ($selector.children(':selected').hasclass('three')) {             $mover.animate({                 "left": "+=50px"             });         };     }); }); 

you can see here.


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -