Display the initial three image components on the HTML webpage, then simply click on the "load more" button to reveal the subsequent two elements

I've created a div with the id #myList, which contains 8 sub-divs each with an image.

My goal is to initially load the first 3 images and then have the ability to load more when clicking on load more.

I attempted to follow this jsfiddle example

Below is my code, similar to the example but not functioning for some unknown reason:

<div id="mylist" class="autoplay123company">

          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="0">

            <img src=" http://realbusinessanalytics.com/wp-content/uploads/2018/07/gtbank__1.jpg" alt="" style="height:100px !important;" width="150" height="100">

          </div>
          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="0">

            <img src=" http://realbusinessanalytics.com/wp-content/uploads/2018/07/partner-MTN.png" alt="" style="height:100px !important;" width="150" height="100">

          </div>
          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="0">

            <img src=" http://realbusinessanalytics.com/wp-content/uploads/2018/07/Partner-airtel.png" alt="" style="height:100px !important;" width="150" height="100">

          </div>
         ...
        </div>
        <div id="loadMore">Load more</div>
        <div id="showLess">Show less</div>
#myList div.col-lg-4 {
  display: none;
}

#loadMore {
  color: green;
  cursor: pointer;
}

#loadMore:hover {
  color: black;
}

#showLess {
  color: red;
  cursor: pointer;
}

#showLess:hover {
  color: black;
}
...

I would appreciate any help in getting it to work. You can view my edited jsfiddle here

Answer ā„–1

The reference in your JS and CSS is to #myList, but the actual ID of the div is mylist. Simply adjust the casing of the div ID and everything should function as intended.

Answer ā„–2

Explaining a simple mistake involving capitalization in an ID #myList in HTML.

$(document).ready(function () {
    size_li = $("#myList div.col-lg-4").size();
    x=3;
    $('#myList div.col-lg-4:lt('+x+')').show();
    $('#loadMore').click(function () {
        x= (x+5 <= size_li) ? x+5 : size_li;
        $('#myList div.col-lg-4:lt('+x+')').show();
         $('#showLess').show();
        if(x == size_li){
            $('#loadMore').hide();
        }
    });
    $('#showLess').click(function () {
        x=(x-5<0) ? 3 : x-5;
        $('#myList div.col-lg-4').not(':lt('+x+')').hide();
        $('#loadMore').show();
         $('#showLess').show();
        if(x == 3){
            $('#showLess').hide();
        }
    });
});
#myList div.col-lg-4 {
  display: none;
}

#loadMore {
  color: green;
  cursor: pointer;
}

#loadMore:hover {
  color: black;
}

#showLess {
  color: red;
  cursor: pointer;
}

#showLess:hover {
  color: black;
}
        <div id="myList" class="autoplay123company">

          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="2">

            <img src="http://realbusinessanalytics.com/wp-content/uploads/2018/07/gtbank__1.jpg" alt="" style="height:100px !important;" width="150" height="100">

          </div>
          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="-2">

            <img src="http://realbusinessanalytics.com/wp-content/uploads/2018/07/partner-MTN.png" alt="" style="height:100px !important;" width="150" height="100">

          </div>
          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="1">

            <img src="http://realbusinessanalytics.com/wp-content/uploads/2018/07/Partner-airtel.png" alt="" style="height:100px !important;" width="150" height="100">

          </div>
          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="-1">

            <img src="http://realbusinessanalytics.com/wp-content/uploads/2018/06/page-1.png" alt="" style="height:100px !important;" width="150" height="100">

          </div>
          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="3">

            <img src="http://realbusinessanalytics.com/wp-content/uploads/2018/07/Partner-citibank.png" alt="" style="height:100px !important;" width="150" height="100">

          </div>
          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="-3">

            <img src="" alt="" style="height:100px !important;" width="150" height="100">

          </div>
          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="-2">

            <img src="" alt="" style="height:100px !important;" width="150" height="100">

          </div>
          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="-1">

            <img src="" alt="" style="height:100px !important;" width="150" height="100">

          </div>
        </div>
        <div id="loadMore">Load more</div>
        <div id="showLess">Show less</div>

Refer to the Working jsfiddle link. Credits to Macros

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue: [ng:areq] The parameter 'PieController' is not properly defined, it is currently undefined

Why am I getting an error when using ng-controller='DoughnutCtrl' in a dive? Error: [ng:areq] Argument 'DoughnutCtrl' is not a function, got undefined Here is my Chart.js code: 'use strict'; angular.module('portfoli ...

Employing pNotify as a seamless substitute for the traditional JavaScript confirmation pop-up

I have successfully implemented inline JavaScript confirmations and also as a function. However, I am struggling to figure out how to integrate PNotify confirmation dialog. My goal is to replace the existing confirm('Sure?') with pconfirm('S ...

The sidebar in tailwind css is not displaying a scrollbar as expected

I'm currently working on a project to create a WhatsApp clone using Tailwind CSS in ReactJS. However, I've encountered an issue with the contacts list where it's not showing the scrollbar and instead overflowing the content, leading to the w ...

How to display and download a PDF file on a JSP web page

Can anyone help me with a simple trick to solve this question I have? In my project folder, I have 5 PDF files named file1.pdf, file2.pdf, file3.pdf, file4.pdf, and file5.pdf. I want to display these files in 5 rows on my webpage, each row containing VIEW ...

Ways to make the Select component in Material-UI lose its focus state once an item has been selected

Anticipated outcome: Upon selecting an item, the Menu list will promptly close, and the Select component will no longer display a focus state. The borderBottom will change to 1px solid, and the backgroundColor will turn to white. Current situation: Sele ...

Unable to create property within array in model

I am facing an issue while trying to access the name property of an array called Model[] generated from my Model.ts file. When attempting to use it in my app.component, I receive an error stating that the property 'name' does not exist on type Mo ...

Tips on sending filter parameters from AngularJS to Spring RestController using @MatrixVariable

Iā€™m struggling to figure out how to use $http.get in AngularJS to pass filter parameters. The URL is: http://localhost:8080/template/users/query;username=abcd;firstName=ding... The RestController looks like this: @RequestMapping(value={"/users/{query ...

Encountering an Issue Executing Selenium Test on jQuery v2.0.2 and Play Framework

While I may not be a selenium expert, it seems that I've stumbled upon a bug when trying to utilize jQuery v2.0.2 with my Play Framework 2.2.1 application instead of the default jQuery v.1.9.0. Whenever I run "play test", I encounter the following err ...

Facing problem with implementing NgMoudleFactoryLoader for lazy loading in Angular 8

A situation arose where I needed to lazy load a popups module outside of the regular router lazy-loading. In order to achieve this, I made the following adjustments: angular.json "architect": { "build": { ... "options": { ... "lazyM ...

Error: The hook call is invalid and can only be made within the body of a function component in ReactJS

Hello everyone, I am currently facing an issue with saving the lat and lng variables in the state within a hook. When trying to do so, I encounter the following error message: "Error: Invalid hook call. Hooks can only be called inside the body of a functio ...

Is utilizing the correct use case for a Bunyan child logger?

I've recently started exploring bunyan for logging in my nodejs application. After giving it a try, everything seems to be functioning quite smoothly. Initially, I overlooked a section on log.child, but now I am eager to understand its usage. It appea ...

AngularJS 500 server error

In my current project, I am developing a straightforward angularjs - J2EE application that fetches data from a mysql server and then displays it on an HTML page. The angular function is triggered on form submission as shown below: <div id="register_for ...

I noticed that when I use jQuery to add a class to an <li> element, the class is added successfully but then quickly removed. I'm wondering if this could be a conflict with

$(document).ready(function() { var $listItems = $('ul li'); listItems.click(function() { $listItems.removeClass('selected'); $(this).addClass('selected'); }); }); .selected{ background color: "green"; } / ...

Innovative sound system powered by React

I am working on implementing a music player feature on a website where users can select a song and have it play automatically. The challenge I am facing is with the play/pause button functionality. I have created all the necessary components, but there see ...

What is the best way to make a trail follow my shapes on canvas?

In my current project, I have implemented a feature where shapes are generated by spinning the mouse wheel. One specific shape in focus is the triangle, but other shapes follow the same generation process. The goal is to create a trail that slowly fades ...

The function canvas.toDataURL() is not recognized - error originating from a node-webGL wrapper

I am currently working on converting client-side volume rendering code in the browser to server-side rendering using pure JavaScript. On the server side, I am utilizing node-webgl. My objective is to send the server's canvas content to the client so ...

Ajax script success function in jQuery

This situation has been frustrating me for the past few days. I'm really in need of assistance. There are 2 files, namely index.php and test.php, and I will provide simplified versions below. index.php <div id="div-greetings"></div> < ...

Issue: ENOENT - The requested file or directory cannot be found in the context of an Angular2 and Express.js

I have made some changes to the Angular2 app on GitHub in order to use Express.js instead of KOA. However, when I try to load the app in FireFox, I encounter the following error in the `nodemon` console: Error: ENOENT: no such file or directory The Angul ...

Setting the thumbnail image for an HTML5 video: A step-by-step guide

Is it possible to set a thumbnail image for an HTML5 video? I would like to display an image before the video starts playing. Here is my current code: <video width="470" height="255" controls> <source src="video.mp4" type="video/mp4"> ...

Exploring the integration of HTML and CSS within the Django framework

Trying to implement a star rating in a specific HTML file The file I am working on is called book_detail.html {% extends "base.html" %} {% load static %} {% block title %} Block Detail Page {% endblock title %} {% block sidenav %} {% for item ...