01Moonlight
-
Posts
5 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by 01Moonlight
-
-
Hi - I'm using the W3 Accordion code with the flowing JS.
<script type="text/javascript">
var acc = document.getElementsByClassName("accordion");
var i;for (i = 0; i < acc.length; i++) {
acc.addEventListener("click", function()
{
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.display === "block") {
panel.style.display = "none";
} else {
panel.style.display = "block";
}
});
}
</script>However, I would like to only have one tab open at a time. I found a script similar to what I'm looking for at:
https://stackoverflow.com/questions/45214002/w3-accordion-auto-close-sections-and-open-close-all
var acc = document.getElementsByClassName("accordion"); var i; for (i = 0; i < acc.length; i++) { acc[i].onclick = function() { if( !this.classList.contains('active') ){ closeAll(); } this.classList.toggle("active"); var panel = this.nextElementSibling; if (panel.style.maxHeight){ panel.style.maxHeight = null; } else { panel.style.maxHeight = panel.scrollHeight + "px"; } } } function openAll(){ for (i = 0; i < acc.length; i++) { acc[i].classList.add("active"); acc[i].nextElementSibling.style.maxHeight = acc[i].nextElementSibling.scrollHeight + "px"; } } function closeAll(){ for (i = 0; i < acc.length; i++) { acc[i].classList.remove("active"); acc[i].nextElementSibling.style.maxHeight = null; } } document.getElementById( 'openAll' ).addEventListener( 'click', openAll); document.getElementById( 'closeAll' ).addEventListener( 'click', closeAll);
However, when I replace the code or put any other JS in, the panels no longer open. I don't know anything about JS so I don't know what's wrong.
Thanks.
-
That's the problem. I have the link in another page that needs to go to the accordion file. How can I do that? I've looked at some java script from other sites but it's either for bootstrap or an accordion created using js.
-
Hi Dsonesuk would that be something like <p><span id="firstlocaiton">My</span>the rest of my paragraph</p> Then where I want to link from: <a href="firstlocation">click here to see the first location</a>
Is this correct?
-
Is there a way to link to a paragraph or word in an accordion tab without using java script?
Link to html accordion panel
in HTML/XHTML
Posted
I looked at the links, but I'm still not sure how that's going to open a panel on another page. I've done what you suggested earlier and it links to the correct page, but does not open the panel.