开发者

Can I use jquery to alternate the color of these fonts?

开发者 https://www.devze.com 2023-03-10 18:06 出处:网络
I am using this function to change the font-size on the class \"tag-link,\" which is numbered like \"tag-link-1\" \"tag-link-2\" etc.

I am using this function to change the font-size on the class "tag-link," which is numbered like

"tag-link-1" "tag-link-2" etc.

So that's why it's using ^

 $(function () {
    $('a[class^="tag-link"]').css('fontSize', '1em');
    });

What I would like to do, however, is also make this function change the font-color of every other tag. Right now, the font-color is blue, but I want it to alternative blue and red for example. It will make the fonts easier to read if they're not all the same color开发者_StackOverflow side by side.

Do you know how to alter this function to make that happen?


Try like this

$(function () {
    $('a[class^="tag-link"]').css('fontSize', '1em');
    $('a[class^="tag-link"]:odd').css('color', '#FF0000');
    $('a[class^="tag-link"]:even').css('color', '#00FF00');
});

or

$(function () {
    $('a[class^="tag-link"]').css({
                                'fontSize':'1em',
                                'color':'#FF0000'
    });
    $('a[class^="tag-link"]:even').css('color', '#00FF00');
});


U can use :even or :odd selectors

$(function () {
    $('a[class^="tag-link"]:even').css('color', '#ff0000');
});


Here's an appropriate manual page: http://api.jquery.com/nth-child-selector/

0

精彩评论

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