jquery - Setting CSS classes as a variable in Javascript for later use? -


i want know if it's possible set css class e.g. ".duck" variable in javascript using jquery e.g. var duck = $(".duck");

i've done "body" tag , css id's doesn't seem work kind of class.

i want set variable later use, have id "#frog" set "var frog = $("#frog");" in javascript can type

frog.moveto(0); frog.speed(0.3); frog.autobounceoff(true); 

but duck class still have use

$(".duck").moveto(270); $(".duck").speed(0.65); $(".duck").oncollision(function(otherobj){ 

is possible set classes variable?

there nothing related css here.

  • duck html class.
  • .duck class selector.
  • $(".duck") function call returns jquery object (containing dom elements, in document, members of class @ time function called).

you can store return value of function call in variable.

a common convention store jquery objects in variables names starting $.

var $duck = $(".duck"); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -