0

I have a div that has some anchors or buttons generated in it, depends on the situation, i need a foucsout event that would detect if some of the div elements got clicked, if not i need to do some logic

i tried this in the focusout event

 $('.navigate-modules-li').find(':active').length == 0

and it works for chrome but not on firefox. :focus and :selected did not work

any ideas? thanks.

Edin
  • 32
  • 8
  • 1
    DIV itself cannot receive "focus". From your description, you are probably looking for another event like "click" ? https://stackoverflow.com/questions/1599660/which-html-elements-can-receive-focus – Filip Matthew Sep 13 '17 at 08:59
  • i dont want to check if the div has focus, i want to check if one of the anchors or buttons inside the div got clicked / active – Edin Sep 13 '17 at 09:02

1 Answers1

0

Not a final solution since it is not completely clear what you are trying to achieve, but below is working example how to "mark" divs with something clicked inside and how to get them afterwards. Hope this will help you to find the way.

$(function() {
  $('.navigate-modules-li > div > a').on('click', function() {
    if (!$(this).parent().hasClass('clicked')) {
      $(this).parent().addClass('clicked').css('background', 'green');
    }
     
    console.log('Divs clicked: ' + $('.navigate-modules-li > div.clicked').length);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="navigate-modules-li">
  <div>
    Div 1
    
    <a href="#">Click me</a> or <a href="#">Click me</a>
  </div>
  <div>
    Div 2
    
    <a href="#">Click me</a> or <a href="#">Click me</a>
  </div>
  <div>
    Div 3
    
    <a href="#">Click me</a> or <a href="#">Click me</a>
  </div>
</div>
Filip Matthew
  • 318
  • 2
  • 8