Trying to write a simple script that will change the background color of an element with a certain class (.global__image-outer-wrap--game-medium) if an "a" within another class and also parent of both (.giveaway__row-outer-wrap) has a certain class (giveaway__column--group) in case when there's multiple elements with (.giveaway__row-outer-wrap).
if ( $(".giveaway__row-outer-wrap,a").hasClass("giveaway__column--group") ){
$(.global__image-outer-wrap--game-medium").css("background-color", "limegreen")};
TL;DR Multiple elements with the same class; I need to select only the ones in which "a" has a certain class.
HTML of the site I'm trying to apply the script to
<div class="giveaway__row-outer-wrap">
<div class="giveaway__row-inner-wrap">
<div class="giveaway__summary">
<h2 class="giveaway__heading">
<a class="giveaway__heading__name" href="/giveaway/fteQx/fahrenheit-indigo-prophecy-remastered">Fahrenheit: Indigo Prophecy Remastered</a><span class="giveaway__heading__thin">(10P)</span><a class="giveaway__icon" rel="nofollow" target="_blank" href="http://ift.tt/1uEkkUE"><i class="fa fa-steam"></i></a><i data-popup="popup--hide-games" data-game-id="3962555" class="giveaway__icon giveaway__hide trigger-popup fa fa-eye-slash"></i>
</h2>
<div class="giveaway__columns">
<div><i class="fa fa-clock-o"></i> <span title="Today, 11:59pm">1 minute remaining</span></div><div class="giveaway__column--width-fill text-right"><span title="February 16, 2015, 4:03pm">4 days ago</span> by <a class="giveaway__username" href="/user/UraniumFalconPunch">UraniumFalconPunch</a></div><a href="/giveaway/fteQx/fahrenheit-indigo-prophecy-remastered/groups" class="giveaway__column--group"><i class="fa fa-fw fa-user"></i></a></div>
<div class="giveaway__links">
<a href="/giveaway/fteQx/fahrenheit-indigo-prophecy-remastered/entries"><i class="fa fa-tag"></i> <span>10 entries</span></a>
<a href="/giveaway/fteQx/fahrenheit-indigo-prophecy-remastered/comments"><i class="fa fa-comment"></i> <span>10 comments</span></a>
</div>
</div><a href="/user/UraniumFalconPunch" class="global__image-outer-wrap global__image-outer-wrap--avatar-small"><div class="global__image-inner-wrap" style="background-image:url(http://ift.tt/1AVMOkS);"></div></a><a class="global__image-outer-wrap global__image-outer-wrap--game-medium" href="/giveaway/fteQx/fahrenheit-indigo-prophecy-remastered"><div class="global__image-inner-wrap" style="background-image:url(http://ift.tt/1vQiFvV);"></div>
</a>
</div>
</div>
There's multiple divs with giveaway_row-outer-wrap class but not all have "a" elements with giveaway__column-group class.
Aucun commentaire:
Enregistrer un commentaire