开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜