The dropdown is instantly opening and closing down when It’s a toggle. I don’t why but It’s asking for the value twice when I looked at it in the console log. I want it to only open once and close when I click on it again.
Link: ( https://www.helionova.co.uk/test-blog )
HTML:
<div class=“container_box”>
<div class=“container_purple”>
<div class=“container_header”>
<div class= “blog_header” >
<h1>
{{ module.blog_listing_header }}
</h1>
<p>
{{ module.blog_header_text }}
</p>
</div>
</div>
</div>
<div class=“filter”>
<li><a class=“btn” href=“https://www.helionova.co.uk/test-blog”>All</a> </li>
<li><a class=“btn” href=“https://www.helionova.co.uk/test-blog/tag/sunbeds”>Sunbeds</a></li>
<li><a class=“btn” href=“https://www.helionova.co.uk/test-blog/tag/rental”>Rental</a></li>
<li><a class=“btn” href=“https://www.helionova.co.uk/test-blog/tag/lamps”>Lamps</a></li>
</div>
<div class=“mobile_btn”>
<span class=“dropbutton”>Show all
<div class= “svg_move”>
<svg width=“9” height=“6” fill=“none” xmlns=“SVG namespace”><path fill-rule=“evenodd” clip-rule=“evenodd” d=“M3.995 5.053.138 1.12A.485.485 0 0 1 0 .777C0 .647.05.526.138.435l.284-.29a.468.468 0 0 1 .67 0l3.24 3.304L7.574.14a.466.466 0 0 1 .67 0l.284.29c.09.091.139.213.139.342 0 .13-.05.251-.139.342l-3.86 3.938a.467.467 0 0 1-.336.141.466.466 0 0 1-.337-.14Z” fill=“#1A1A1A”></path></svg>
</div>
</span>
<div id=“dropdown__list-show” class=“dropdown_content”>
<a href=“https://www.helionova.co.uk/test-blog”>All</a>
<a href=“https://www.helionova.co.uk/test-blog/tag/sunbeds”>Sunbeds</a>
<a href=“https://www.helionova.co.uk/test-blog/tag/rental”>Rental</a>
<a href=“https://www.helionova.co.uk/test-blog/tag/lamps”>Lamps</a>
</div>
</div>
<div class=“content-wrapper”>
<div class=“blog-index”>
{% for content in contents %}
<div class=“blog-index__postblog-index__post–small”>
{% if not simple_list_page %}
<div class=“blog-index__post-inner-card{% if not content.featured_image %} no-image{% endif %}”>
{% if content.featured_image %}
<a class=“blog-index__post-image” style=“background-image: url(‘{{ content.featured_image }}’)” href=“{{ content.absolute_url }}”>
</a>
{% endif %}
<div class=“blog-index__post-content blog-index__post-content–small”>
{% if content.tag_list %}
<div class=“blog-post__tags”>
{% for tag in content.tag_list %}
<a class=“blog-post__tag-link” href=“{{ blog_tag_url(group.id, tag.slug) }}”>{{ tag.name }}</a>{% if not loop.last %},{% endif %}
{% endfor %}
</div>
{% endif %}
<div class = “content_title”>
<p>
<a href=“{{ content.absolute_url }}”>{{ content.name }}</a>
</p>
</div>
<div class=“content_text”>
{{ content.post_list_content|truncatehtml(100)|striptags|safe }}
</div>
</div>
<div class=“author_readtime”>
<img alt=“{{ content.blog_post_author.display_name }}” src=“{{ content.blog_post_author.avatar }}” class=“author_icon”>
<span class=“author_name”> By <strong>{{ content.blog_post_author.display_name }}</strong></span>
<span>\ \• \ </span>
<span class=“readtime”>
{{ content.post_body|split(’ ',5000)|length|divide(250)|round(0,‘ceil’) }} minute read
</span>
</div>
</div>
{% else %}
<h2 class=“post-listing-simple”><a href=“{{content.absolute_url}}”>{{ content.name }}</a></h2>
{% endif %}
</div>
{% endfor %}
</div>
{% if contents.total_page_count > 0 %}
<div class=“blog-pagination”>
{% set page_list = [-2, -1, 0, 1, 2] %}
{% if contents.total_page_count - current_page_num == 1 %}{% set offset = -1 %}
{% elif contents.total_page_count - current_page_num == 0 %}{% set offset = -2 %}
{% elif current_page_num == 2 %}{% set offset = 1 %}
{% elif current_page_num == 1 %}{% set offset = 2 %}
{% else %}{% set offset = 0 %}{% endif %}
{% if current_page_num == 1 %}{{ blog-pagination__prev-link--disabled }} {% endif %}
<a class=“blog-pagination__link blog-pagination__prev-link {{ “blog-pagination__prev-link--disabled” if !last_page_num }}”{% if !last_page_num %} {% else %} href=“{{ blog_page_link(last_page_num) }}” {% endif %}>
{% icon name=“chevron-left” style=“SOLID”, width=“13”, no_wrapper=True %}
</a>
{% for page in page_list %}
{% set this_page = current_page_num + page + offset %}
{% if this_page > 0 and this_page <= contents.total_page_count %}
<a class=“blog-pagination__link blog-pagination__number-link {{ “blog-pagination__link--active” if this_page == current_page_num }}” href=“{{ blog_page_link(this_page) }}”>{{ this_page }}</a>
{% endif %}
{% endfor %}
<a class=“blog-pagination__link blog-pagination__next-link {{ “blog-pagination__next-link--disabled” if !next_page_num }}” {% if !next_page_num %} {% else %} href=“{{ blog_page_link(current_page_num + 1) }}” {% endif %}>
{% icon name=“chevron-right” style=“SOLID”, width=“13”, no_wrapper=True %}
</a>
</div>
{% endif %}
</div>
</div>
Javascript:
$(function(){
var numEx = window.location.pathname.split(‘/’);
var pN = numEx[numEx.length - 1]
if (window.location.href.indexOf(“test-blog”) > -1){
var current = location.pathname.replace(‘/page/’ + pN, ‘’ );
console.log(current)
$(‘.filter .btn’).each(function(){
var $this = $(this);
if (current == ‘/test-blog’ && $this.attr(‘href’) == ‘https://www.helionova.co.uk/test-blog’){
$this.addClass(‘active’);
} else if ($this.attr(‘href’).indexOf(current) !== -1 && current !== ‘/test-blog’){
$this.addClass(‘active’)
}
})
}
})
Mobile view dropdown function:
$(function(){
$(‘.dropbutton’).click(function(){
$(this).parent().find(‘#dropdown__list-show’).slideToggle();
})
});