JavaScript array images are not showing when using the img tag

For this module, I am working on creating a flipbook (magazine) using images stored in a JavaScript array. However, I am facing an issue where the images are not loading up properly. Instead of displaying the image, it shows as [object" htmlimageelement]="". I have checked and confirmed that the directory for my images is correct. It seems like there might be something missing in my JavaScript code.

HTML:

<html>
    <head>      
        <title>Flipbook</title>     
        <link href="jqmodule.css" type="text/css" rel="stylesheet" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script src="jqmodule.js" type="text/javascript"></script>      
        <script src="jquery.easing.1.3.js" type="text/javascript"></script>
        <script src="jquery.booklet.latest.js" type="text/javascript"></script>     
    </head>
    <body class="body_div">
        <div class="container">         
            <div class="main clearfix">
                <div class="custom_wrapper">
                    <h3>Flipbook</h3>
                    <div id="mybook" class="booklet"></div>             
                </div>
            </div>
        </div>      
    </body>
</html>

JS:

var heading=['background-size','Using transform and the transform functions','Audio','CSS 1, CSS 2.1, CSS3 ...','The benefits of CSS3'];
    var para = new Array();
    para[0] = new Image();
    para[0].src = 'images/1.jpg';
    para[1] = new Image();
    para[1].src = 'images/2.jpg';
    para[2] = new Image();
    para[2].src = 'images/3.jpg';
$(function() {  
    var str="";
    for(var i=0;i<para.length;i++)
    {
        str+="<div class=\"b-page-blank\"><h1>"+heading[i]+"</h1><img src="+para[i]+"/></div>";                                 
    }
    $('#mybook').html(str);
    $('#mybook').booklet({ name: "Booklet" });  
    $(".b-counter").click(function(){   
        if($(this).attr('id')==2||$(this).attr('id')==4)
        {           
            $("#mybook").booklet("next");           
        }
        if($(this).attr('id')==3||$(this).attr('id')==5)
        {           
            $("#mybook").booklet("prev");
        }       
    });
});

Answer №1

Trying out this method may offer a cleaner and more troubleshoot-friendly approach,

var info = [
    {title:'Responsive design',picture:'/images/1.jpg'}, 
    {title:'CSS transformations',picture:'/images/2.jpg'}, 
    {title:'Video integration',picture:'/images/3.jpg'}
    // ...
];

$(function() {  
    var content="";
    $.each(info,function(index,item){
        content+="<div class=\"b-page-blank\"><h1>"+item.title+"</h1><img src=\""+item.picture+"\" /></div>";                                 
    })
    $('#mybook').html(content);
    //... remainder of code
});

Give it a try, hope this suggestion proves useful.

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

"Utilize Ajax and PHP to seamlessly upload a PDF file directly into a MYSQL database

I am trying to figure out how to upload a pdf file from user input into my MySQL database. I have provided code that displays a user registration form with the option to upload a PDF file. My goal is to use AJAX to post this data to a PHP script for storag ...

When the search button is clicked to find a specific address, the React Google Maps API fails to zoom in on

How can we modify this code to achieve the functionality where, upon clicking the search button, the map zooms in closer to the address entered by the user, similar to how it works on Google Maps? The goal is to replicate the search feature from the Goog ...

Dim the entire website

I am attempting to apply a grey overlay across my entire site when a file is dragged in for upload. The drag event and activation of the grey overlay are functioning correctly, but there are specific areas where it does not work as intended. There seems t ...

How can I utilize a JSON object in Scala to establish a database connection through JavaScript?

Recently diving into Scala and Play, I am currently learning how to work with a JSON object. I need to send this JSON object to my Scala controller class and then connect it to the database for storage. However, I'm not quite sure how to go about doin ...

Using Node.js with Express to seamlessly pass objects to EJS templates

I have a scenario where I am passing an object to my template and I want to display the details of that object in HTML. app.get('/', function (req, res) { var user = req.session.passport.user; if ( user != 'undefined' ){ ...

What is the best way to ensure that a PDF document automatically opens when a webpage is visited?

I am fairly new to this, so please be patient with me. What I am attempting to achieve is the automatic opening of a PDF document as soon as a webpage is loaded. Both the webpage and the PDF document(s) will be stored locally. We are working with an exter ...

Elements appear with varying widths in Firefox compared to Webkit-based browsers

I believe it would be simpler for you to inspect the elements rather than me writing the code, so I have provided a link: music band site. Now onto the issue: When the window width is reduced in Firefox, you will notice that the social icons in the yellow ...

What is the method for adding an event listener in AngularJS within an ng-repeat iteration?

I'm completely new to AngularJS and currently working on building a photo gallery. The basic idea is to have an initial page displaying thumbnail photos from Twitter and Instagram using an AngularJS ng-repeat loop. When a user hovers over an image, I ...

Is it possible to alter the parent scope from an AngularJS directive?

I am currently in the process of constructing my initial Angular application, but I am encountering some difficulties while attempting to achieve a specific functionality. The issue revolves around a video container which is supposed to remain hidden until ...

Which is better: express.Router() or app.get() for serving routes

I am currently working with Express 4 server for Node.js Express comes with a built-in router, which is utilized as follows: in app.js var router = express.Router(); app.use(router); app.use('/users', usersRoutes); in userRo ...

The hidden overflow seems to be inconsistently effective

I've been working on creating some buttons with a rollover state. I have an image inside a div with overflow:hidden to hide the inactive state, but sometimes it doesn't work properly. What's even stranger is that when I inspect the page usi ...

open a new window with a reference based on the name

In order to obtain a reference to the currently open window, I utilize the following code: var refWindow = window.open("mypage1", "name_mypage"); If I wish to close the window, I simply use this command: refWindow.close(); When I refresh the screen (by ...

Implementing this type of route in Vue Router - What are the steps I should take?

I am currently delving into Vue and working on a project that involves creating a Vue application with a side menu for user navigation throughout the website. Utilizing Vue Router, my code structure looks like this: <template> <div id="app ...

Deleting a division with the help of media queries

As a challenge, I am attempting to eliminate the .navbar-brand>img element once the screen size exceeds 768px by using media queries. Unfortunately, my efforts have not been successful so far. Although the styling applied to the img is successfully remo ...

JavaScript: Transform an Array of Strings into an Array of Objects

Here is an array containing different strings: let myArray : ["AA","BB" , "CC" ...] My goal is to transform it into an array of objects: myArray = [{"id":1 , "value": "AAA"},{"id":2 , "value": "BBB"},{"id":3 , "value": "CCC"}...] I attempted to achiev ...

A menu offering interactive features such as hover effects, click functionality, dynamic class changes, and

Take a look at the latest simplified code snippet below, which I hope will benefit someone: $("#menu").find("a").hover(function(){ $(this).addClass("active"); },function(){ $(this).not(".clicking").not(".selected").removeClass("active"); }); $ ...

Unexpected issue on AngularJS application

Encountering issues with incorporating a controller into my page - each time I add it to a DOM element, an error is thrown. Here's the structure of my HTML page: <html data-ng-app="sportsStore"> <head> <title>Sports Sto ...

Verification of three-dimensional password format with the use of AngularJS

I am trying to implement password validation in Angular.js that requires a combination of alphabetical, numerical, one upper case letter, one special character, no spaces, and a minimum length of 8 characters. How can I achieve this using Angular.js? Here ...

I am encountering a situation in which the controller file is returning empty data when logging the contents of req

User Model const mongoose = require("mongoose"); const userSchema = mongoose.Schema( { name: { type: String, required: true }, email: { type: String, unique: true, required: true }, password: { type: String, required: true }, pic: { ...

Display child component automatically upon parent component state update

The main component Dashboard manages the state for each ListItem added to my Watchlist. However, whenever I add an item, it is inserted into the database but only appears when I refresh the browser. class UserDashboard extends React.Component { state = ...