I have a number of pages with lessons listed like this:
<div class="et_pb_module">Page Title</div>
<div class="insert-after"></div>
<div class="lesson-container">
<div class="et_pb_module">
<div class="content">
Lesson 1
</div>
</div>
<div class="et_pb_module">
<div class="content">
Lesson 2
</div>
</div>
<div class="et_pb_module">
<div class="content">
Lesson 3
</div>
</div>
<div class="et_pb_module">
<div class="content">
Lesson 4
</div>
</div>
</div>
If there is a specific lesson called in the URL's query string I want only that lesson to be shown on the page:
E.g. foo.com/lessons?lesson1
should only show "lesson 1"
I've got an IF statement in jQuery working that does this:
if (window.location.href.indexOf("?lesson1") > -1) {
$('.et_pb_module').hide();/*Hide all lessons*/
$('.lesson-container .et_pb_module:nth-of-type(2) .content ').insertAfter('.insert-after'); /*Select content from first lesson and place it at top of the page after 'insert-after'*/
}
This works fine but will involve me having to cut and past the above up to nine times updating the query string and :nth-of-type
selector each time creating lots of repetitious code.
Is there a way I can use an array to compress this process?
Thanks for any feedback.