Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initializing Raphael object with jQuery selector

In Raphael docs, we init Raphael with:

var paper = Raphael(document.getElementById("notepad"), 320, 200);

I want to select my class with jQuery and turn it to Raphael, so my thought is:

var paper = Raphael($(".myClass"), 320, 200);

But I get TypeError: b is undefined in Raphael.js. Does anyone know how to do this?

like image 556
Rizky Ramadhan Avatar asked Jan 07 '11 03:01

Rizky Ramadhan


1 Answers

Try:

var paper = Raphael($(".myClass")[0], 320, 200);

The $ function returns an array-type object of HTML elements, so use [0] to get the first.

like image 169
Sophie Alpert Avatar answered Oct 28 '22 05:10

Sophie Alpert