Having trouble toggling journal entries in an HTML journal? The Jquery function might not be working properly

I have been tasked with creating a civil war journal for my 8th grade Social Studies class and I decided to present it as an HTML file featuring the title and date of each journal entry. The goal is to allow users to click on each entry to open it while automatically closing any other open entries. However, I am encountering issues with making the journal entries expand upon clicking. Below is the code I have written so far. (P.S. Some journal entries are still a work in progress.)

UPDATE: The code functions correctly in JSFiddle, but is not working when viewed in a browser.

HTML

<html>
<head>
    <link href="http://s3.amazonaws.com/codecademy-content/courses/ltp2/css/bootstrap.min.css" rel="stylesheet">
    <link rel='stylesheet' href='journal.css'/>
    <title>Pericby Zarby Journal</title>
</head>
<body>
    <div id='container'>
        <div class='entry current'>
            <div class='item row'>
                <div class="col-xs-3">
                    <p class='date'>July 22, 1861</p>
                </div>
                <div class='col-xs-6'>
                    <p class='title'>The Battle of Bull Run</p>
                </div>
            </div>
            <div class='description row'>
                <div class="col-xs-3">&nbsp;</div>
                <div class="col-xs-6">
                    <p>As I step through the door of the steel mill, I overhear the conversation that my boss and one of my co-workers are having. 
                        I hear something about a battle and the start of a civil war. I walk by and suddenly my friend Joe runs up to me and says, 'Did ya hear?' 
                        I give him a funny look that shows how confused I am. He proceeds to tell me about the Battle of Bull Run. 
                        He says that a small skirmish between the Union and Confederate armies happened in Virginia. He also says that the Union lost. 
                        That last part really surprises me. The North is supposed to have a lot more men than the South and should have destroyed the South. 
                        Hopefully the rest of the war does not go like this.</p>
                </div>
                <div class='col-xs-3'>&nbsp;</div>
            </div>
        </div>
        <div class='entry'>
            <div class='item row'>
                <div class='col-xs-3'>
                    <p class='date'>December 15, 1862</p>
                </div>
                <div class='col-xs-6'>
                    <p class='title'>Fredericksburg</p>
                </div>
            </div>
            <div class='description row'>
                <div class='col-xs-3'>&nbsp;</div>
                <div class='col-xs-6'>
                    <p>While I am drinking and talking with some of the other blacks in the 86th regiment, I spot a small man running up to Colonel Smith 
                        and telling him that General Burnside needs reinforcements. Smith shouts for everyone to get into formation and begin marching towards 
                        Fredericksburg. After about an hour of marching I am finally able to see a battlefield, but it does not look pretty. 
                        A group of Union soldiers is charging towards a Confederate barricade. One by one, each soldier is getting killed. 
                        No progress is made by the soldiers. My regiment begins to line up in formation for another charge. As Burnside begins to realize that the 
                        charge before is proving futile he barks a command to retreat. My regiment marches in an orderly fashion back to the nearest Union camp.</p>
                </div>
                <div class='col-xs-3'>&nbsp;</div>
            </div>
        </div>
        <div class='entry'>
            <div class='item row'>
                <div class='col-xs-3'>
                    <p class='date'>January 2, 1863</p>
                </div>
                <div class='col-xs-6'>
                    <p class='title'>Emancipation Proclamation</p>
                </div>
            </div>
            <div class='description row'>
                <div class='col-xs-3'>&nbsp;</div>
                <div class='col-xs-6'>
                    <p>It’s official. Lincoln has released the Emancipation Proclamation. Slaves from     states in rebellion are now free. 
                        Southern plantations won’t let that happen though. No slaves are going to be freed, yet. The best thing about the Emancipation Proclamation 
                        is that now slaves have something to fight for. They will begin to help win this war, in big and small ways. 
                        Also, France and Great Britain can’t help the South anymore because they are slave-free countries. 
                        Lincoln may have just given the Union the boost they need to win this civil war. I know it has given me hope.</p>
                </div>
                <div class='col-xs-3'>&nbsp;</div>
            </div>
        </div>
    </div>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="journal.js"></script>
</body>
</html>

CSS

body {
    position: fixed;
    background-image: url("http://housedivided.dickinson.edu/grandreview/wp-content/uploads/2010/02/HD_4USCinfantryDetail.preview.jpg");
    background-size: cover;
}
#container {
    height: 700px;
    width: 600px;
    border-right: 3px black solid;
    border-left: 3px black solid;
    border-bottom: 3px black solid;
    position: fixed;
    margin: 10px auto;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
}
.row {
    margin: 0;  
}
.current .item{
    background-color: rgba(112,112,112,0.7);
}
.entry {
    background-color: rgba(216, 209, 209, 0.7);
    border-top: 3px solid black;
}
.item {
    cursor: pointer;
    padding-top: 7px;
    padding-bottom: 18px;
}
.description {
    display: none;
    padding-top: 10px;
    padding-bottom: 10px;
}
.item .date {
    margin-left: 20px;
    font-weight: bold;
    font-style: italic;
}
.item .title {
    font-weight: bold;
    font-size: 20px;
    text-align: center;
}

Javascript

var main = function() {
    $('.entry').click(function() {
        $('.entry').removeClass('current');
        $('.description').hide();

        $(this).addClass('current');
        $(this).children('.description').show();
    });
}
$(document).ready(main);

Answer №1

If you are working on your local machine, you might need to modify the following line:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

to:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

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

I have come to realize that my understanding of how Sass nesting works was misguided

Currently struggling with understanding Sass nesting. Any explanations on where I went wrong would be greatly appreciated, as this is a beginner-level issue for me. Thank you in advance. .header { display: flex; height: 10vh; background-color: #13192 ...

Increase the value by one of the number enclosed in the <h3> element

I have a variable number of <h3> tags with the same class .love_nummer <h3 class="love_nummer">1</h3> Each of these tags contains a number, and alongside each .love_nummer tag is another tag with the class .give_love <h3 class="give ...

Here is a method to transform the JSON object into a string as demonstrated below:

Presented below is a JSON object: { "category": "music", "location": { "city": "Braga" }, "date": { "start": { "$gte": "2017-05-01T18:30:00.000Z" }, "end": { "$lt": "2017-05-12T18:30:00.000Z" } } } I am looking t ...

Obtain JSON data from an API and display it in a table using axios and Vue.js

I am working with a datatable and trying to populate it with data fetched from an API that returns JSON using the findAll() method from Sequelize. However, when I call the getUser method in console.log, it shows that the data is being retrieved. But when ...

Select a file and upload an image promptly after it is chosen

Is there a way to automatically upload an image once a user selects a file in their browser? Similar to how it works on Facebook, where users can choose a file for their cover or profile image and then the upload process begins. Currently, all I have is ...

Automatically adjusting the image to fit the screen size

The image on the screen is not resizing properly. Please refer to the image with the alternate text google-play-badge. Even though the width and height of the image are set to auto, it is still not adjusting automatically. Here are my codes: body { ...

Give a radio button some class

<input id="radio1" type="radio" name="rgroup" value="1" > <label for="radio1"><span><span></span></span>1</label> <input id="radio2" type="radio" name="rgroup" value="2" > <label for="radio2"><span ...

Dynamic resizing in NextJs does not trigger a re-render

My goal is to dynamically pass the width value to a component's styles. Everything works fine on initial load, but when I resize the window, the component fails to re-render even though the hook is functioning as intended. I came across some informat ...

How do I iterate through my state in React Redux?

Currently, I am delving into Redux by creating a to-do list in React. I have been pondering on the utilization of the map function to iterate over the state so that I can display the data stored within different div elements. Here is my initial state: cons ...

Toggle draggable grid in jQuery

Imagine I have a grid set up using the following code: $( "#dragIt" ).draggable({ grid: [ 15, 15 ] }); Now, there is a checkbox located below the div. Is there a way for me to switch the grid on and off by toggling the checkbox? I've searched the of ...

Should ng-binding be avoided in CSS selectors as a general rule?

Recently, I stumbled upon this code snippet in our codebase: li.ng-binding span { font-size: 13px; font-family: Arial, Helvetica, sans-serif; font-weight: bold; } The selector above doesn't actually apply to one of the intended 'li& ...

Ways to prevent the need for multiple if/else statements and repetitious function instances

Check out this code snippet in Javascript: https://pastebin.com/zgJdYhzN. The purpose of the code is to fade in text when scrolling reaches a specific point. While it does work, I want to optimize it for multiple pages without creating separate instances ...

I keep encountering a 404 error whenever I try to access a controller method using Ajax. What could be causing this

In my ValidationController, there is a method named EmailExist. I made an ajax call to the following URL: $.ajax({ type: "POST", url: "/Validation/EmailExist", data: { 'Email': $('#Email').val() }, success: fun ...

Adding a character at the beginning of each loop iteration in a nested array with Vue.js

When working inside a v-for loop, I am attempting to add a character at the beginning of each item in a nested array that may contain multiple items. I have explored various options but have not been successful: :data-filter="addDot(item.buttonFilter ...

Ways to display pictures by invoking an API within the antd item list container

Upon page load, I am fetching images from a database using an API. Now, my goal is to display these images within a Modal in Antd. How can I accomplish this with the code snippet below? const MyVehiclePage = (props) => { useEffect(() => { co ...

Importing CSS into the styles section of angular.json is no longer feasible with Angular 6

Currently in the process of migrating a project to Angular 6, I'm facing an issue with importing my CSS file within the styles section of angular.json: "styles": [ "./src/styles.css", "./node_modules/primeng/resources/primeng.min.css", ...

Rendering JSON data in a dropdown menu

When I select an option, all the data is being combined into one row. I want the data to fill each row based on the select option. Any suggestions on what code I should modify or add? Is it related to the loop or should I create a dynamic id for the selec ...

no output upon completion of a class constructor - JavaScript

I am facing a perplexing issue with my code. Let me break it down for you: class Block{ constructor(timeStamp, lastBlockHash, thisBlockData, thisBlockHash){ this.timeStamp = timeStamp; this.lastBlockHash = lastBlockHash; this.t ...

Is it possible to execute jQuery or Angular functions using WWW::Mechanize::Firefox?

When attempting to run jQuery/Angular calls using WWW::Mechanize::Firefox's eval_in_page, I am encountering errors that suggest a scope issue. For example, if I try to execute the following code: angular.element(document.getElementsByClassName("inpu ...

What is the best way to use jQuery to adjust the size of a slider image based on a percentage of the browser window

I've been searching all over for a solution to this issue, but so far I haven't had any luck. Basically, I have an image that is 1800 pixels wide by 500 pixels high. I need this image to adapt to all screen resolutions. Instead of having a fixed ...