开发者

Get link tag returns error

开发者 https://www.devze.com 2023-04-01 15:18 出处:网络
Why does this return an error? <link rel=\"shortcut ic开发者_C百科on\" type=\"image/x-icon\" href=\"gfx/favicon.ico\" />

Why does this return an error?

<link rel="shortcut ic开发者_C百科on" type="image/x-icon" href="gfx/favicon.ico" />

var link = $('link[rel=shortcut icon]');

error:

uncaught exception: Syntax error, unrecognized expression: [rel=shortcut icon]


You need to put the value of rel in quotes:

var link = $('link[rel="shortcut icon"]');

See the jQuery docs on attribute selectors:

jQuery('[attribute="value"]')

attribute An attribute name.

value An attribute value. Quotes are mandatory.

0

精彩评论

暂无评论...
验证码 换一张
取 消