I have one question with my code.
I created this DEMO from jsfiddle.net
When you click the red div, a menu will open, but if you click the menu items, the menu area will not be closed.
What do I need to close the menu area when I click on the menu?
<div class="p_change" tabindex="0" id="1"> <div class="pr_icon"><div class="icon-kr icon-globe"></div>CLICK</div> <div class="pr_type"> <div class="type_s change_pri md-ripple" data-id="0"><div class="icon-pr icon-globe"></div>1</div> <div class="type_s change_pri md-ripple" data-id="1"><div class="icon-pr icon-contacs"></div>2</div> <div class="type_s change_pri md-ripple" data-id="2"><div class="icon-pr icon-lock-1"></div>3</div> </div> </div> <div class="p_change" tabindex="0" id="2"> <div class="pr_icon"><div class="icon-kr icon-globe"></div>CLICK</div> <div class="pr_type"> <div class="type_s change_pri md-ripple" data-id="0"><div class="icon-pr icon-globe"></div>1</div> <div class="type_s change_pri md-ripple" data-id="1"><div class="icon-pr icon-contacs"></div>2</div> <div class="type_s change_pri md-ripple" data-id="2"><div class="icon-pr icon-lock-1"></div>3</div> </div> </div>
Js
$(document).ready(function() { $('.pr_icon').on('click',function(e){ // Change Post Privacy $('.change_pri').on('click',function(event){ event.stopPropagation(); var dataid = $(this).attr('data-id'); var id = $(this).closest('.p_change').attr('id'); var class_name = $(this).find(".icon-pr").attr("class"); class_name = class_name.replace(/icon\-pr\s+/gi, ""); $(this).closest(".p_change").find(".icon-kr").removeClass().addClass("icon-kr " + class_name); $.ajax({ type: "POST", url: "change_id.php", data: { dataid : dataid, id: id } }).success(function(html){ if (html.trim() === "1") { // Do Something } else { // Do something } }); }); });
source share