Hi, I have this script in js that adds a class to these two classes to change the style when clicking on the div that has the letterBox class.
The question is I want to remove the alphabetical class, which is the one I put when they click on any other place than letterboxes.
<script type="text/javascript">
(function($){
$(document).ready(function(){
$(".cajasLetras").click(function () {
$('.cajasLetras').addClass('alphabetical');
$('.Linearicons-Free-text-format').addClass('alphabetical');
});
});
})(jQuery)
</script>
<div class="cajasLetras">
<div class="dropdown-menu-letras">
<span class="topbar-text">
<i class="Linearicons-Free-text-format"></i> ALPHABETICAL
</span>
</div>
</div>
When I click on this div, the alphabetical class is added to letterboxes, but when I try to removeClass, the addClass stops working.
not()
You can use the ( info ) method to get those elements that are of one type and not of another. In this case you would select all the elementsdivs
except those that have the classcajasLetras
and add the click event to remove the class to the elements with classcajasLetras
withremoveClass()
( removeClass info )edit
I update with what the OP asks for. An easy option to remove the class when you click on anything other than the div
cajasLetras
is to make the withdiv
focusabletabindex="-1"
and then use the eventfocusout
on thediv
.Here more info about
tabindex="-1"
I use this function to hide and show an element, in this case it is a counter. I use the events
onblur()
andonfocus()
that the element offers<input>
(also applies to a textarea, as it is in this case). Try it and adapt it to your project, it may be useful if you don't tell me, greetings!The theme is events
onblur()
andonfocus()
, which work the way you propose. Clicking on any other side of the page removes a value from an element, in the example I gave you it hides and shows an element. In your case you would have to do the opposite so that the style you want to change changes when you click elsewhere on the site, respectively.