I have two divs of class pagediv. Inside are divs (#myDIV1, #myDIV2) for innerHTML injection.
I’d like to turn the other pagedivs to display:none when a button in the one pagediv is selected. This will be similar to an SPA operation of hiding all the other divs to show just the page selected. Then clicking (tapping) another button will remove all display:none to show all the buttons again. Simplified example:
The best css I can come up with is this.
.pagediv :not(#myDIV2) {display:none;}
.pagediv #myDIV2 {display:block;}
Unfortunately, it hides all the buttons for both pagedivs rather than just the pagediv button containing myDIV1. I suspect I am supposed to use > or < in the CSS some way, but I haven’t found the reference page for these yet. If it’s on this page, I missed it: https://www.w3.org/TR/css-2017/#selectors
Once I can get the CSS right, then I’ll work on trying to implement that in a JS function. In case you want to know the context, I expect to integrate the CSS and function into this codepen: https://codepen.io/iPhoneDevLog/pen/rvJQYg
I need to rethink my approach then. I suppose I could put the button’s parent selector ID in the DB as I did the innerHTML ID. Calling one will call the other.
Out of curiosity, what would be the advantage over doing this with JS alone? I mean you still need the JS, plus a lot of copy/paste in the CSS that has to reflect the values set by JS…
I mean… your JS at that point is reduced to “document.getElementById(“hiddenfield”).value = ‘A’”, so its readability has gotta be pretty strong.
It can definitely lead to some extended CSS (if you have a lot of values that the input could be). If you’re doing it with a couple of fixed values, not as much.
EDIT: Also i’ve realized the environment my example was working in was also running scripts (beyond my control) that automatically replaced values of same-name fields, so in my environment <select name='selecteditem'><option>A</option><option>E</option></select> would have done all the work for you. Not true in a standard environment (though it would be mightily handy if it was)
Hm… I’d argue that the opposite is the case; like, when you toggle a class you can search for that class name in the CSS, but here it’s not immediately obvious how this relates to CSS (or that it does in the first place). Anyway, thanks for clarifying! :-)