使用jQuery选择器初始化Raphael对象

Riz*_*han 10 jquery jquery-selectors raphael

在Raphael docs中,我们通过以下方式启动Raphael:

var paper = Raphael(document.getElementById("notepad"), 320, 200);
Run Code Online (Sandbox Code Playgroud)

我想用jQuery选择我的课并将其转到Raphael,所以我的想法是:

var paper = Raphael($(".myClass"), 320, 200);
Run Code Online (Sandbox Code Playgroud)

但我进入TypeError: b is undefinedRaphael.js.有谁知道如何做到这一点?

Sop*_*ert 12

尝试:

var paper = Raphael($(".myClass")[0], 320, 200);
Run Code Online (Sandbox Code Playgroud)

$函数返回HTML元素的数组类型对象,因此用于[0]获取第一个元素.