开发者

Check anchor tags color

If I have anchor tags as follows:

<a href="link1.html" class="none_standard_links">link one</a><br />
<a href="link2.html" class="none_standard_links">link two</a><br />
<a href="link3.html" class="none_standard_links">link three</a><br />
<a href="link4.html" class="none_standard_links">link four</a><br />
<a href="link5.html" class="none_standard_links">link five</a><br />
<a href="link6.html" class="none_standard_links">link six</a><br />
<a href="link7.html" class="none_standard_links">link seven</a><br />
<a href="link8.html" class="none_standard_links">link eight</a><br />
<a href="link9.html" class="none_standard_links">link nine</a><br />
<a href="link10.html" class="none_standard_links">link ten</a><br />

How do I loop through the entire set and alert the url of the link if it has a style sheet color of red?

I have tried making a start with the script, but don't know how to finish off:

$(document).ready(function(){
    $('#button1').click(function() {
        $(".none_standard_links").each(function (i) {
            if (this.style.color = "red") {
                alert("not sure what to do here?");
            }
        });
    });
});

If the approach I am attempting is not the best way to go about doing this, 开发者_StackOverflow社区please feel free to make changes.


if (this.style.color == "red") Will never work coz it's reading inline style, not style applied from stylesheets.

May I ask what are you trying to achieve here? Aren't stylesheets designed by you, and you should know the color?

The only thing I can think of that you wanna do is to detect a visited link. In that case, a:visited { padding: 10px 0 } with $('a')[0].offsetHeight should do it.


Got it working as follows:

$('#button').click(function() {
    $(".none_standard_links").each(function (i) {
        if ($(this).css("color") == "red") {
            alert($(this).attr("href"));
        }
    });
}); 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜