javascript - first website, need assistance with certain click function -


i have 2 tabs on option. have created mouseover , mouseleave these 2 tabs. when highlight 1 or other, share background color.

however, creating click function. when click on 1 of these tabs, maintain background color, , if user highlighted second time, not change color time. reason want show tab active, because each have own seperate content appear clicked within same div.

html code:

<div class="meal-details">   <h4>lobster & summer vegetables spicy herbed butter</h4>   <h5 class="optiontabs meal-description">description</h5>   <h5 class="optiontabs nutrition-description">nutritional info</h5>   <div class="nutrition-breakdown">     <p>this nutrition info bro</p>   </div>   <div class="meal-breakdown">     <p>the meal breakdown , descrition.</p>   </div> </div> 

jquery:

$(document).ready(function() {    $(".optiontabs").mouseover(function() {     $(this).css("background-color", "#3e597c");    });    $(".optiontabs").mouseleave(function() {     $(this).css("background-color", "#141c25");    });    $(".nutrition-description").click(function() {     $(this).css("background-color", "#3e597c");     $(this).nextall(".nutrition-breakdown").css("display", "initial");     $(this).nextall(".meal-breakdown").css("display", "none");   });  }); 

my question is, best method use in order achieve have mentioned above. have asked jquery change background-color of active tab not doing it. doing wrong?

thanks in advance!

you have unbind mouseover , mouseleave once click on element once. can using $('element').off('event') syntax. please @ following code:

$(document).ready(function() {      var countclick = 0;      if(countclick==0) {         $(".optiontabs").mouseover(function() {         $(this).css("background-color", "#3e597c");       });        $(".optiontabs").mouseleave(function() {         $(this).css("background-color", "#141c25");       });     }      $(".nutrition-description").click(function() {         $(".optiontabs").off("mouseleave");         $(".optiontabs").off("mouseover");         countclick++;         $(this).css("background-color", "#3e597c");         $(this).nextall(".nutrition-breakdown").css("display", "initial");         $(this).nextall(".meal-breakdown").css("display", "none");     });  }); 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -