开发者

jquery find link by rel

开发者 https://www.devze.com 2022-12-11 11:35 出处:网络
i have some links in my page < a class=\"Qlink\" rel=\"20;5\" href=\"javascript:void(0);\">5</a>

i have some links in my page

< a class="Qlink" rel="20;5" href="javascript:void(0);">5</a>
< a class="Qlink" rel="21;6" href="javascript:void(0);">6</a>
< a class="Qlink" rel="22;7" href="javascript:void(0);">7</a>

i do some ajax call and get the 开发者_如何学JAVAfirst number on the rel attribute(exp. 20)

how do i can change the class of link (the first in my exp.)


$("a[rel^='20;']").addClass('foo');

See also: attributeStartsWith


A combination of Kobi and Soufiane's answers will do what the OP is asking:

$("a[rel^=20]").attr('class', 'your_new_class');

He asked to change the class, after all.


If you mean that you want to change the class attribute of your links:

$('a.Qlink').attr('class','your_new_class');

Edit: Based on the other answers, this one is better :

$('a[rel^=20]').attr('class','your_new_class');
0

精彩评论

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