2011-09-01 98 views
2

爲什麼會返回錯誤?獲取鏈接標記返回錯誤

<link rel="shortcut icon" type="image/x-icon" href="gfx/favicon.ico" /> 

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

錯誤:

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

回答

3

你需要把價值rel引號:

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

jQuery docs的屬性選擇:

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

attribute An attribute name.

value An attribute value. Quotes are mandatory.