I have the following HTML content on the FAQ page.
<div id="block-companysubtheme-content" class="block block-system block-system-main-block panel o-box">
<article data-history-node-id="1576" about="/services/faq">
<div class="node__content">
<div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item">
<h2>General</h2>
<ul class="list--faq">
<li aria-controls="faq-0" aria-expanded="false" tabindex="0">How can I contact the company with questions about your services?</li>
<li id="faq-0" style="display: none;">Please contact us through phone.</li>
<li aria-controls="faq-1" tabindex="0" aria-expanded="true">How old does parts need to be for food testing?</li>
<li id="faq-1" style="display: none;">There is no time limit for testing.</li>
<li aria-controls="faq-2" aria-expanded="false" tabindex="0">What is the cost of services?</li>
<li id="faq-2" style="display: none;">The cost of services varies. See the information page specific for the details</li>
<li aria-controls="faq-3" aria-expanded="false" tabindex="0">What are my payment options?</li>
<li id="faq-3" style="display: none;">You can pay online or mail a check.</li>
</ul>
</div>
</div>
</article>
</div>
Notice that all the answer list elements have style
set to display:none;
as shown above. Once used clicks on the question, let’s say I clicked on this question <li aria-controls="faq-0" aria-expanded="false" tabindex="0">How can I contact the company with questions about your services?</li>
, then the CSS of its answer changes to the following:
<li id="faq-0" style="display: block; transition: all 300ms ease-in 0s;" data-slide-toggle="true">Please contact us through phone</li>
Overall, the above shared HTML content will look like this with the open question:
<div id="block-companysubtheme-content" class="block block-system block-system-main-block panel o-box">
<article data-history-node-id="1576" about="/services/faq">
<div class="node__content">
<div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item">
<h2>General</h2>
<ul class="list--faq">
<li aria-controls="faq-0" aria-expanded="false" tabindex="0">How can I contact the company with questions about your services?</li>
<li id="faq-0" style="display: block; transition: all 300ms ease-in 0s;" data-slide-toggle="true">Please contact us through phone</li>
<li aria-controls="faq-1" tabindex="0" aria-expanded="true">How old does an animal need to be for DNA testing?</li>
<li aria-controls="faq-1" tabindex="0" aria-expanded="true">How old do parts need to be for food testing?</li>
<li id="faq-1" style="display: none;">There is no time limit for testing.</li>
<li aria-controls="faq-2" aria-expanded="false" tabindex="0">What is the cost of services?</li>
<li id="faq-2" style="display: none;">The cost of services varies. See the information page specific for the details</li>
<li aria-controls="faq-3" aria-expanded="false" tabindex="0">What are my payment options?</li>
<li id="faq-3" style="display: none;">You can pay online or mail a check.</li>
</ul>
</div>
</div>
</article>
</div>
What I am trying to achieve is the following:
If a user is directed to this page from an external website with the URL, let’s say: http://localhost:8080/services/faq#faq-0
, then I want to expand the list for them.
The way I am attempting it like this in my javascript code:
var hash = window.location.hash;
alert(hash);
$(hash).show();
But this does nothing. So do I need to specifically insert the CSS style="display: block; transition: all 300ms ease-in 0s;" data-slide-toggle="true"
for the list element with id
faq-0
using jQuery? Is that the way to proceed?