Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid the inline style using jquery or javascript

How to remove these two inline style beside the .dropdwon menu, I tried the remove attribute [ jQuery('.dropdown-menu').removeAttr('style'); ] unfortunately it doesn't remove the inline style. Every time I hover the nav the inline style change to display block and when it hover out the inline style is set to display:none

<ul role="menu" class=" dropdown-menu" style="display: none;">
<ul role="menu" class=" dropdown-menu" style="display: block;">

Here's my code. I'm trying to remove this on size 767 or mediaquery max-width(767)

jQuery(window).resize(function() {
    var width = jQuery(window).width();
    if( width < 767 ) {
      jQuery('.dropdown-menu').removeAttr("style");
    }
});

jQuery(document).resize(function() {
    var width = jQuery(document).width();
    if( width < 767 ) {
      jQuery('.dropdown-menu').removeAttr("style");
    }
});

please see the two attached image for better visualization

When I hover the nav(About) the subpage show(ul.dropdown-menu) and the inline style will set to display block enter image description here

When I hover out the nav(About) the subpage (ul.dropdown-menu) inline style will set to display none enter image description here

Please help me get rid these two inline style the style="display:none"; and style="display:block";

like image 910
Melvin Rey Avatar asked Feb 04 '23 08:02

Melvin Rey


2 Answers

Try with show()

jQuery('.dropdown-menu').show()

or css()

jQuery('.dropdown-menu').css('display','block')

Drag the output window of the fiddle .They will show the menu on resize

Demo Fiddle

like image 107
prasanth Avatar answered Feb 16 '23 04:02

prasanth


There is a JavaScript somewhere that is adding those styles. I guess you are using some framework or template you found in the Internet. Now you either have to remove the not-needed code that adds the styles (recommended!) or bind over it to be removed each time, something like what you have written but in different event:

jQuery('.dropdown-menu').hover(function() {
      jQuery('.dropdown-menu').removeAttr("style");
}, function() {
      jQuery('.dropdown-menu').removeAttr("style");
});

Ensuring this is after the piece of code that does the style adding at first place.

Or you can try totally removing the behaviour for the menu and write your own:

jQuery('.dropdown-menu').unbind();
like image 35
Samuil Petrov Avatar answered Feb 16 '23 04:02

Samuil Petrov