user10 user10 - 6 months ago 11
CSS Question

how to add current class selected div in jquery

Codepen Demo



here i used hover function on
jquery
. it works correctly. but i need selected
li
on hover div.

$('.block-templates-container:not(:first-child)').hide();
$(".block-name").each(function() {
$(this).hover(function() {
$('.block-templates-container').hide();
var getId = $(this).attr('id');
$('.block-templates-container#' + getId + '_show').show();
});
});


when i hover rightside block(heading design,content design) the
li
not selected. how to fix this?

Answer

Try by adding class on hover

  //Sidebar 
  $('.block-templates-container:not(:first-child)').hide();
      $(this).hover(function() {
          $('.block-templates-container').hide();
          var getId = $(this).attr('id');
          $('.block-templates-container#' + getId + '_show').show();

          $('.block-name').not(this).removeClass('current');
          $(this).addClass('current');
      });
  });