2
I have a problem here and I don’t know how to solve, in theory, in my role below 768px
was to add the class .navbar-inverse
the tag nav
, and above 768px
is to remove it if it exists, but nothing happens.
Edit: I did some tests and I saw that he is ALWAYS removing this class and so it is giving problem.
My JS is like this:
$(document).ready(function () {
$(window).resize(function () {
var $element = $("nav");
/*Abaixo de 768px, add a classe .navbar-inverse*/
if (window.innerWidth < 768) {
if(!$element.hasClass(".navbar-inverse")) {
$element.addClass(".navbar-inverse")
}
}
/* Acima de 768px, se existir a classe navbar-inverse ela é retirada*/
if (window.innerWidth > 768) {
if($element.hasClass(".navbar-inverse")) {
$element.removeClass(".navbar-inverse")
}
}
});
});
I can’t see the problem, the tag nav
there is, but nothing happens.
If you resize the screen works?
– Oeslei
Nope, n matter the resolution I resize the screen it n works.
– Andrey Hartung
While current responses solve your immediate problem, you’ve considered using media queries instead of adding/removing classes via Javascript? (sometimes you can’t avoid JS, but if it’s just a matter of styling the components based on screen resolution, a pure CSS solution is preferable)
– mgibsonbr
Already, I use, but the layout was bugging below 768px. I’m using the bootstrap to make the layout and to make it look good below 768px I had to add this class to adapt the layout for mobile users.
– Andrey Hartung