This can probably best be described from the images I attached to this post. I don’t know how to create this window or what it would be called when clicking on the ‘Adv. FIlter’ button. As seen below the ‘Adv Filter’ button
You would create the panel as a hidden element in your html (using html and css) and then when the button is clicked you can toggle a class on the panel that will allow you to make the panel visible.
It is similar to most menus or dropdown arrangements. Of course the filter functions are beyond my scope and will need considerable work but here is the basic of how to show a panel when a button is clicked.
Hi this doesn’t seem to be working. When I click the button I get ‘Uncaught Type Error: Cannot read property ‘addEventListener’ of null’ on line 7 of the js code. I added everything else html,css.
The codepen isn’t working for you? It works in all my browsers.
You are not using IE8 or something similar are you as the js is for modern browsers?
Unless you meant that you have copied the code locally and your local code isn’t working? If this is the case we need to see your code as you have probably copied something incorrectly.
No I’m using Chrome. I did copy your code. I put the js in it’s own .js file and included it in the html head. Does it matter, didn’t think it would. Still get the same error if I put it in html code.
This is the js I copied
(function (d) {
"use strict";
if ("querySelector" in document && "addEventListener" in window) {
var theFilter = d.querySelector("#advanced-filter-button");
var theFilterParent = d.querySelector("#advanced-filter");
var closeButton = d.querySelector("#close");
theFilter.addEventListener(
"click",
function (e) {
theFilterParent.classList.toggle("open-filter");
},
false
);
closeButton.addEventListener(
"click",
function (e) {
theFilterParent.classList.toggle("open-filter");
},
false
);
}
})(document);
Only the head exists when the js is run and therefore does not find any html to work with. Always include your own scripts at the end of the html as I have shown above even for external scripts.
You can only add scripts in the head when they have been designed to wait for the page to load but it is much safer and better practice to place them at the end of the html as shown.
I don’t get any errors but now when I click on the ‘Adv. Filter’ button it flashes the menu quick and goes away. I’ve tried changing the css but nothing seems to work. Why is it doing that?
Hopefully you are still around. Everything is working great so far. I did have one thing I needed help with on your code pen on this page and this is the close button. I wanted to make that say ‘Cancel’ and it basically does the same thing as close but it’s not a button but like a link or label. Then right beside it I want to have an ‘Apply’ button. How do I configure that?
Remove the background, borders,padding, dimensions and colours and it will just be text (background:transparent;border:none; etc…). Then change the text in the button as required and style to suit.
Remember links are for navigating to somewhere and buttons are for actions so don’t confuse or misuse the two.
The example of how to style the button is already in the codepen so you should be able to create another button exactly the same (or styled to suit) quite easily. You can just place it next to the other one with absolute positioning or create a parent for both buttons and absolutely place that instead. I used absolute positioning so the buttons could be at the bottom but you do need to make sure that content doesn’t over-write them.
You need to start getting your hands dirty and experimenting so that you can learn more than just me giving you code
How you handle the action of actually applying whatever it is you have in your form is a programming task and beyond my scope. It’s more a question for the JS forum if that’s what you meant.