2

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');
   });

3 Answers 3

1

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');
}
Sign up to request clarification or add additional context in comments.

1 Comment

hi this work ~ but everyone I click is white , how if when element is not selected return to color #666 back ?
1

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');
     }

 });

Comments

0

You may be referring to:

window.document.getElementByClassName("allgametap_wrapper").style.color = white;

A bit tricky to understand what you mean.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.