Reputation: 2979
Is that possible to change other element css
when element has selected. For example the code bellow have div.allgametap_wrapper
, inside have div.allgame_tabitem
,div.clear
and div.tabtitle
. What I mean is I have using js to switch the class selected
inside div.allgame_tabitem
, when div.allgame_tabitem
has class selected
the div.tabtitle
inside it self div.allgametap_wrapper
will change to css #fff (white)
.
<div class="allgametap_wrapper">
<div class="allgame_tabitem onlinegametab"></div>
<div class="clear"></div>
<div class="tabtitle" style="color:#666;"></div>
</div>
<div class="allgametap_wrapper">
<div class="allgame_tabitem allgametab selected"></div>
<div class="clear"></div>
<div class="tabtitle" style="color:#666;"></div>
</div>
JS Switch Selected Code
$(".allgame_tab_container div div.allgame_tabitem").on('click', function (e) {
e.preventDefault();
var $this = $(this);
$(".allgame_tab_container div div.allgame_tabitem").removeClass('selected');
$this.addClass('selected');
});
Upvotes: 2
Views: 546
Reputation: 951
here is shorthand code for that
$("div.allgame_tabitem").on('click', function(e) {
e.preventDefault();
if ($(this).hasClass('selected')) {
$(this).siblings('.tabtitle').css('color', '#fff');
} else {
$(this).addClass('selected');
$(this).siblings('.tabtitle').css('color', '#fff');
$(this).parent().siblings().find('.selected').removeClass('selected');
}
});
Upvotes: 1
Reputation: 9060
It would be great If you can provide the js code of yours. Here is the illustration :
// $(this) would refer to current selected element
// this depend on your existed js code
if ( $(this).hasClass('selected') ) {
$('.tabtitle').css('color','#666'); //<-- add this
$(this).siblings('.tabtitle').css('color','#fff');
}
Upvotes: 1
Reputation: 15238
You may be referring to:
window.document.getElementByClassName("allgametap_wrapper").style.color = white;
A bit tricky to understand what you mean.
Upvotes: 0