3

次のようなリンクがたくさんあります。

<a href="http://www.youtube.com/user/nigahiga">Youtube</a>
<a href="http://pinterest.com/pin/41236152807615600/">Pinterest</a>
<a href="https://www.facebook.com/manchesterunited">Facebook</a>
<a href="http://www.youtube.com/user/RayWilliamJohnson">Youtube</a> 
<a href="http://pinterest.com/pin/24910604158520050/">Pinterest</a>

にリンクされるハイパーリンクのみをスタイルする方法を教えてpinterestください。私はこれを試しました:

$('a').attr('href').contains('pinterest').css('Styling here');

しかし、うまくいきません。それを達成する方法は?

4

5 に答える 5

1
  $('a[href*="pinterest"]').css('apply styles');

セレクターのドキュメントは、http://docs.jquery.com/Selectorsにあります。

For attributes:

= is exactly equal
!= is not equal
^= is starts with
$= is ends with
*= is contains
于 2013-04-25T13:23:15.627 に答える
0

次のセレクターを使用して、pinterest にリンクされたすべてのハイパーリンクを取得できます。

$('a[href^="http://pinterest.com/"]')

そのセレクターは、「href」属性がhttp://pinterest.com/で始まるすべての「a」要素を返します。

次に、それらをスタイルできます

于 2013-04-25T13:20:48.427 に答える
0

属性 contains solution の代わりに (きれいではありませんが)、フィルター関数を使用することもできます。

$('a').filter(function () {
    return $(this).attr("href").indexOf("pinterest") != -1;
}).css('color', 'red');

これが実際の例です

于 2013-04-25T13:21:16.703 に答える
0

すべての a の href 属性値を確認する必要があります。

$('a').each(関数(){

if($(this).attr('href').contains('pinterest'))

$(this).css (あなたのスタイル);

});

于 2013-04-25T13:39:01.990 に答える