This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Aravind Ravi
Posted Jun 08 - Read on Facebook

I have a layer with html like this. Is there a way to dynamically use a query selector to select the span element and add a click event to it?

layer = new Layer
html: 'This text is <span class="myStyle">Styled</span>'

5 Comments

Steve Ruiz

Yes, it's possible to use jQuery with Framer, though the two libraries tend to step on eachother's toes. The simplest way I've found is by bringing in jQuery as an npm module (see the documentation for how to do this), then doing something like the code below. Just entering the code alone won't do anything - you'll need to create the module first.

Aravind Ravi

Thanks Steve Ruiz! That's helpful. Is it possible to add an onclick event listener that's a Coffeescript function?

Steve Ruiz

surprisingly... yes. I always thought that the layer would accept and absorb the click event, but by turning off ignoreEvents, we can receive our jquery click events.

Aravind Ravi

That's brilliant, thank you!

George Kedenburg III

just FYI you can do most things with vanilla JS these days, no need to mess with jquery: http://youmightnotneedjquery.com/

Read the entire post on Facebook