开发者

jQuery Selector issue finding href with text category1 in it

开发者 https://www.devze.com 2022-12-30 19:43 出处:网络
i have a set of hyperlinks with href = javascript:method(\'category1\') and likewise category2 category3 ...

i have a set of hyperlinks with href = javascript:method('category1') and likewise category2 category3 ...

I want to select hyperlink with href containing category1 so i have written

jQuery(a[href*='category1']) but dont know why it also selects hyperlinks with category10 category11 ca开发者_开发知识库tegory12 ... also

I understand that category1 is common in all of them but 'category1' should'nt be do i need to put ' with escape charaters.


jQuery("a[href=javascript:method('category1')]");

Just do = if you only want category1, and define the entire href.

Also, you're missing the outer quotation marks.


EDIT:

Alternatively, you could use the 'attribute ends with' selector if you want to shorten it up a bit.

jQuery("a[href$=('category1')]");


How about adding an id to each hyperlink to easier select them?


Use the Attribute contains selector.

$("a[href*=category]");
0

精彩评论

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

关注公众号