Jump to content


Do I need jQuery to easyly select my elements - It works without it

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts



I was under the impression that for convenience when selecting elements you could use jQuery. In other words by using jQuery you could select your elements like this ...

TweenLite.from(".some-class", 1, {scale:2.0});

instead of ...

var myClass = document.getElementById(".some-class");
TweenLite.from(myClass, 1, {scale:2.0});

The reason for my question is because I just tried selecting my elements like ".class-name" and it worked without having jQuery linked.


See my Codepen.


See the Pen gdbkr by fs_tigre (@fs_tigre) on CodePen

Link to comment
Share on other sites

Hello fs_tigre, and welcome to th GreenSock forum!


Yes you are correct.. starting with GSAP version 1.13.1 .. you now use any CSS selector inside the target  parameter of your tween.


The below taken from this page: http://greensock.com/gsap-1-13-1


Save kb by skipping jQuery. Default selector: document.querySelectorAll()


Probably the most common reason that developers load jQuery is to leverage it as a selector engine but all modern browsers support document.querySelectorAll(), so as of version 1.13.1, GSAP uses that as a fallback (after attempting to detect a selector engine like jQuery). That means that you can do something like this, for example:

// Without loading jQuery
TweenLite.to("li:first-child, li:last-child", 1, {opacity:0.5});


Just make sure you are using GSAP 1.13.1 or higher to take advantage it.


Hope this helps! :)

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.