Error: SyntaxError: DOM Exception 12 on Tag Creation Using jQuery

隐身守侯 提交于 2019-12-05 01:33:55

Make sure you have jQuery loaded in your first example.

Even if you don't have jQuery loaded, the function $() is now defined by Google Chrome as something similar to querySelectorAll().

This function only accepts a CSS selector as parameter and not arbitrary HTML like jQuery's $().

From the docs:

SYNTAX_ERR code 12 In invalid or illegal string has been specified; for example setting the selectorText property of a CSSStyleRule with an invalid CSS value.

The function is expecting a CSS selector and you gave it HTML so it gave a syntax error.

See this fiddle, it works just fine:

http://jsfiddle.net/S6d6w/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!