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

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

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -