0

DOM 要素の配列があり、それらを反復処理して jQuery を使用してクラスを追加しようとしていますが、jQuery は addClass メソッドでクラスを設定していないようです。ただし、attr 関数は引き続き機能します。私は何を間違っていますか?

これがコンソールからの私の結果です。

jQuery addclass が機能しない

http://jsfiddle.net/kf77m/1/

line 64
$(ui).addClass("class", "js-tooltip");
4

2 に答える 2

0

jquery のソースを見ると、この動作は #8317 に起因すると考えられます。

elem.className = finalValue;

SVG 要素にこのプロパティがないことを確認すると、クラスは設定されません (または、特定の行は引き続き実行されますが、何も実行されません)。

詳細については、コメントを参照してください。

于 2014-07-04T18:49:52.167 に答える
0

いずれかの犬が私を投稿に打ち負かしたので、jQuery はelement.className. 問題は、SVG 要素がelement.className値を として扱うことですreadonly。つまり、jQuery がクラスを設定しようとしても何もしません。

if ( elem.className !== finalValue ) {
    elem.className = finalValue;
}

https://github.com/jquery/jquery/blob/master/src/attributes/classes.js#L46を参照してください

RECT要素はSVGRectElementインターフェースを実装します:

interface SVGRectElement : SVGElement,
                           SVGTests,
                           SVGLangSpace,
                           SVGExternalResourcesRequired,
                           SVGStylable,
                           SVGTransformable {
  readonly attribute SVGAnimatedLength x;
  readonly attribute SVGAnimatedLength y;
  readonly attribute SVGAnimatedLength width;
  readonly attribute SVGAnimatedLength height;
  readonly attribute SVGAnimatedLength rx;
  readonly attribute SVGAnimatedLength ry;
};

http://www.w3.org/TR/SVG/shapes.html#InterfaceSVGRectElement

SVGRectElementSVGStylableこれには、次のちょっとした情報が含まれます。

className (readonly SVGAnimatedString)

http://www.w3.org/TR/SVG/types.html#InterfaceSVGStylableを参照

于 2014-07-04T18:57:41.773 に答える