How to hide pagination with Javascript

I am trying to hide my bootstrap pagination bar if the search results in less than one page of items.

this is my home.html pagination:

<div class="pagination" id="paginationField">
            <nav aria-label="...">
                <ul class="pagination", id="pagination">
                    <li class="page-item {% if not prev_page_url %}disabled {% endif %} ">
                        <a class="page-link" href="{{ prev_page_url }}" tabindex="-1">Previous</a>
                    </li>
                    {% for n in page.paginator.page_range %}
                        {% if page.number == n %}
                            <li class="page-item active">
                                <a class="page-link" href="?page={{ n }}">{{ n }} <span class="sr-only">(current)</span></a>
                            </li>
                        {% elif n > page.number|add:-3  and n < page.number|add:3 %}
                            <li class="page-item">
                                <a class="page-link" href="?page={{ n }}">{{ n }}</a>
                            </li>
                        {% endif %}
                    {% endfor %}
                  
                  <li class="page-item {% if not next_page_url %}disabled {% endif %} ">
                    <a class="page-link" href="{{ next_page_url }}">Next</a>
                  </li>
                </ul>
            </nav>
        </div>

Here is my js file:

function showHidePagination() {
if(document.getElementById('paginationField').length > 15) {
    document.getElementById('pagination').style.display='none';
} else {
    document.getElementById('pagination').style.display='block';
}

}

Answer

probably need to check for document.getElementById(‘paginationField’).innerHTML.length instead of document.getElementById(‘paginationField’).length

Leave a Reply

Your email address will not be published. Required fields are marked *