I looked about multiple existing posts and none had a solution for me.
Edit: Someone asked why I'm using jQuery(document).ready(function($). This is a Wordpress site. You have to wrap your jQuery like this if you want to use $ since $ is used by the Wordpress framework and will break your code.
Update
Here is the code that creates the button dynamically. I wouldn't have done it this way, but I've inherited the site when I started working here:
$('nav').before('<button class="menu-btn" role="button" aria-pressed="false"><span>toggle menu</span></button>');
$('nav .sub-menu').before('<button class="sub-menu-toggle" role="button" aria-pressed="false"></button>');
Not only are the styles not being applied, they are not even visible in dev tools so I know they're not simply being overridden by inline styles or something. The jQuery css isn't being loaded at all.
Details:
- There are no errors in the console log.
- No errors when ran through JS Hint
- Chrome debugger shows the code executed
- Chrome Elements tab does not show the styles as loaded
.site-title's styles are applied perfectly.menu-btnis not applying at all.
jQuery(document).ready(function($) {
$('.site-title').css({
'grid-column-start': '2',
'grid-column-end': '6'
});
$('.menu-btn').css({
'top': 'unset',
'right': 'unset',
'left': '10px',
'bottom': '15px',
'z-index': '100',
'position': 'fixed'
});
});
When the same styles are added via CSS they apply correctly.
body > div.site-container > button.menu-btn {
top: unset;
right: unset;
bottom: 15px;
left: 10px;
z-index: 100;
position: fixed;
}
jQuery(function($) { /.../ });.$is used by the Wordpress framework so you have wrap your jQuery in that if you want to use$.jQueryand allows you to reference a local copy. This is useful where there's are conflicting libraries fighting for$, or you released jQuery's control of that variable using$.noConflict(). Here's a more obvious example: jsfiddle.net/qocmy91x.on()- api.jquery.com/on