admin管理员组文章数量:1417032
I'm currently implementing CodeMirror and I'm trying to use the addLineWidget
function.
It's second parameter takes a DOM Node
, so I thought to construct it with jQuery like this:
var widget = $('<span class="ct-description-widget">' + descr + '</span>').get();
However, when I pass it to the function, it throws an exception:
TypeError: Value does not implement interface Node.
How can I make it a true Node
? Note that I cannot append it anywhere into the DOM!
I'm currently implementing CodeMirror and I'm trying to use the addLineWidget
function.
It's second parameter takes a DOM Node
, so I thought to construct it with jQuery like this:
var widget = $('<span class="ct-description-widget">' + descr + '</span>').get();
However, when I pass it to the function, it throws an exception:
TypeError: Value does not implement interface Node.
How can I make it a true Node
? Note that I cannot append it anywhere into the DOM!
- @billyonecan oh, that did it. I should have seen the square brackets in firebug :) – MarioDS Commented May 28, 2013 at 8:37
-
2
@billyonecan: Did you meant
.get(0)
?? – palaѕн Commented May 28, 2013 at 8:37 - @PalashMondal .get()[0] give same result as .get(0) of course but the usual syntax is to pass index as param – A. Wolff Commented May 28, 2013 at 8:42
1 Answer
Reset to default 5I dont know codemirror and not sure what you call a true node. But to return the first DOM element matched, you need to use get(0):
var widget = $('<span class="ct-description-widget">' + descr + '</span>').get(0);
This is equivalent to:
var widget = $('<span class="ct-description-widget">' + descr + '</span>')[0];
本文标签: javascriptCreating a DOM element with jQuerydoes not implement quotnodequotStack Overflow
版权声明:本文标题:javascript - Creating a DOM element with jQuery - does not implement "node"? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745267817a2650708.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论