Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
Javascript: Get value from URL and parse it into function

I have a filter function for a portfolio gallery. It looks like this:

<script type="text/javascript">
    $(document).ready(function(){
        $('.filterlist').click(function(){
            const value = $(this).attr('speaker-filter');
            if (value == 'all'){
                $('.speakers-element').show('1000');
            }
            else{
                $('.speakers-element').not('.'+value).hide('1000');
                $('.speakers-element').filter('.'+value).show('1000');
            }
        })
        // add active class on selected item
        $('.filterlist').click(function(){
            $(this).addclass('active').siblings().removeClass('active');
        })
    })
</script>

The code is taken from this YouTube video: https://www.youtube.com/watch?v=ZjrqnxDEkzA

Now I would like to get a parameter from the URL (like ?section=film) to prefilter by URL. Unfortunately I didn't get it running until now, so I would be happy for any tips around that.

Thank you!

@Andreas: Sorry! I tried this code

function getParameterByName(name, url = window.location.href) {
    name = name.replace(/[\[\]]/g, '\\$&');
    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
var value = getParameterByName('section');

I tried it before $(document).ready(function(){ and after that line (within this function), and in a separate <script></script>.

@ruleboy21: HTML: The buttons are done this way:

<div class="container">
 <ul>
  <li class="btn btn-sm filterlist active" speaker-filter="all">All</li>
  <li class="btn btn-sm filterlist" speaker-filter="section1">Section 1</li>
  <li class="btn btn-sm filterlist" speaker-filter="section2">Section 2</li>
 </ul>
</div>

The portfolio element has this code:

<div class="container">
 <div class="row is-flex speakers-line">
  <div class="section1 section2 col-sm-3 speakers-element" id="speakername">
     (Content)
  </div>
 </div>
</div>

This is the only CSS on speakers-element:

.speakers-element {
  padding-right: 1px !important;
  padding-left: 1px !important;
  margin-bottom: 1px;
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!