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" }); }; }); });
a couple of things:
- what need conditional
if
statement, that's basic of language. - 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" }); }; }); });
Comments
Post a Comment