开发者

jQuery a[href=#/example] does not select all matching anchors - cross-browser issue

开发者 https://www.devze.com 2023-02-15 12:44 出处:网络
So I\'m trying to get jQuery to make the following selection: $(\"a[href=#/example]\") and I have an anchor <a href=\"#/example\">ex</a>.

So I'm trying to get jQuery to make the following selection:

$("a[href=#/example]")

and I have an anchor <a href="#/example">ex</a>.

When I try this selector out in chrome, IE8开发者_StackOverflow社区, FF, or other browsers it works fine, but when I goto test it in IE6/7, and other older browsers, the selector doesn't work because the browser interprets the anchor's href attribute as http://example.com/#/example

What's a graceful way to solve this issue for all browsers?


Use the ends-with attribute selector:

$("a[href$=#/example]")
0

精彩评论

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

关注公众号