JavaScript how to addClass to closest element add class to closest element jquery,closest element addclass

You need to change the selector

$(".submenu.in").closest(".menu").addClass("in");

Alternatively :has() selector can also be used as

Selects elements that contain at least one element that matches the specified selector.

$(".menu:has(.submenu.in)").addClass("in");
Answer:1

Try this:

For looking up the DOM use this:

<script>
    $('.submenu.in').closest('.menu').addClass("in");
</script>

For looking into the children elements use this:

<script>
    $('.submenu.in .menu').first().addClass("in");
</script>
Answer:2

I am using google.maps.places.Autocomplete in my mobile app as part of an input field at the bottom of the screen. when the user focuses on the input field the virtual keyboard appears shortening the ...

I am using google.maps.places.Autocomplete in my mobile app as part of an input field at the bottom of the screen. when the user focuses on the input field the virtual keyboard appears shortening the ...

  1. javascript autocomplete suggestions
  2. input autocomplete suggestion

Javascript focus is not working in my code. HTML <div class="col-md-6" style="border:none; margin-top:2px; padding-right:5px"> <input type="text" id="edtunt" ng-model="Unit" class="...

Javascript focus is not working in my code. HTML <div class="col-md-6" style="border:none; margin-top:2px; padding-right:5px"> <input type="text" id="edtunt" ng-model="Unit" class="...

  1. javascript focus not working
  2. javascript focus not working in chrome
  3. javascript focus not working ios
  4. javascript focus not working in firefox
  5. javascript focus not working safari
  6. javascript focus is not working
  7. javascript focus not working on input
  8. javascript focus not working on div
  9. javascript focus isn't working
  10. javascript focus not working on mobile
  11. javascript focus not working ipad
  12. javascript focus event not working
  13. javascript focus element not working
  14. javascript focus method not working
  15. javascript focus function not working
  16. javascript focus button not working
  17. javascript focus textarea not working
  18. javascript focus select not working
  19. javascript focus method not working in firefox
  20. javascript focus textbox not working

I searched on stackoverflow a bit and couldn't find an exact answer to this problem. I have some tabs on my webpage. I want when a user clicks a tab to place an active tag on the tab the user picked ...

I searched on stackoverflow a bit and couldn't find an exact answer to this problem. I have some tabs on my webpage. I want when a user clicks a tab to place an active tag on the tab the user picked ...

  1. issue tabs jira
  2. session issue with multi tabs in a browser
  3. issue tabs
  4. issue tabs redmine

I have a redux container which I want to mount in my test case. It has a component which is using react-router link. Mounting the container was throwing me history not defined error, after reading ...

I have a redux container which I want to mount in my test case. It has a component which is using react-router link. Mounting the container was throwing me history not defined error, after reading ...