There is a html code

<div class="choose-ral"></div> <div class="option option-image"> <ul> <li data-value="1366" class=""></li> <li data-value="1368" class=""></li> <li data-value="1369" class="selected"></li> </ul> </div> 

When you click on any of the elements $ ('. Option-image ul li'). Click to hide the block $ ('. Choose-ral'). Hide ('slow'); but hide only if it is not <li data-value="1369" class="selected">

I tried this code

 $('.option-image ul li').click(function() { if ($('li[data-value=1386]').not('.selected')) { $('.choose-ral').hide('slow'); } }); 

The element is hidden, but when you click on any of the li in that isle and .select

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

I did this:

 $('.option-image ul li').click(function(){ var $this = $(this); if ($this.attr('data-value') == '1369' && $this.hasClass('selected')) { return false; } $('.choose-ral').hide('slow'); // скроет блок внутри li //$('.choose-ral', $this).hide('slow'); // скроет весь li //$($this).hide('slow'); }); 

Living example:

http://codepen.io/bustexz/pen/rezRaN?editors=1010

Ps. If you hide an element inside li, the element disappears and the empty li remains.

  • Thank you, but I still have the same effect, the mod div is hidden when you click on any li. I do not need to hide the li elements, there is a separate <div class = "choose-ral"> </ div> block that you need to hide if you click on li with bast except that selected and data-value = "1369" - animal_x
  • I wrote comments in the code. The last lines indicate what to hide. A code that will hide the whole li in which there is a class .choose-ral commented out //$($this).hide('slow'); - Vasily Barbashev
  • .choose-ral is outside li is a separate unit - animal_x
  • Emae, in your example is this block (as I see it not)? Add an example, I will look. - Vasily Barbashev
  • Sori, missed, added in the first post <div class = "choose-ral"> </ div> - animal_x
 $('.option-image ul li').not('.selected').click(function(){ $('.choose-ral').hide('slow'); }); 

Work Example: http://codepen.io/zoinx2012/pen/VazOVK