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

Intermittent functionality observed with jQuery mobile swipe feature

I have implemented swipe events using jQuery mobile 1.3.2, where I slide the note_container left/right with each swipe. However, I am facing issues with the swipe event registration on Samsung Galaxy S3 and other android devices, as it is intermittent and ...

JavaScript allows for the manipulation of elements within a webpage, which includes accessing elements from one

There is a file that contains a fragment for the navbar. The idea is to have listItems in the navbar, and upon clicking on those listItems, another subnavigationbar should open below it. Below is the code I currently have: <!DOCTYPE html> <html x ...

Interactive table on click

Seeking assistance with an issue involving a combobox (select) and a dynamic table generated from PHP. The table displays names along with their Firstname, Lastname, and ID (hidden). Upon clicking on a row in the table, I should retrieve the ID of that spe ...

Ways to retrieve a value from the column within the editor's template of a Kendo.Grid when it loses focus or onblur()?

I'm working with a grid that has an editor template in my HTML setup. Whenever I click on a column, it switches to edit mode, enabling me to modify the value in the textbox. My specific query is, how can I retrieve the value of $50.00 using jQuery up ...

Two boxes each taking up half of the width, with content placed inside a container

How can I achieve the appearance seen in this image? The layout consists of four columns using regular Bootstrap code. The first two columns should have a white background within a .container, while the other two columns should have a black background tha ...

jQuery Form Validator: requiring double submission

I've been working on implementing the Form Validator using Jquery. After some testing, I noticed that I have to click the submit button twice before the validation kicks in. Why is that? The script is housed in a separate file and included in my proj ...

Unfortunately, the datepicker feature does not seem to work properly on elements that have been dynamically added through the

My code progress so far is as follows: $('body').on('change', '.dropdown', function() { $.ajax({ success: function(res) { if(res.success == true) { return elements that have the class ...

Dynamically uploading an HTML file using AJAX

My webpage has a feature that dynamically creates HTML with drop down elements. Additionally, there is a "create File" button on the page. The goal is for this button to trigger an AJAX POST request and upload the dynamic page created with drag and drops a ...

The React component designed to consistently render video frames onto a canvas is unfortunately incompatible with iOS devices

I'm facing an issue with my code snippet that is supposed to draw video frames on a canvas every 42 milliseconds. It's working perfectly on all platforms and browsers except for iOS. The video frames seem unable to be drawn on canvas in any brows ...

AgGrid Encounters Difficulty in Recovering Original Grid Information

After making an initial API call, I populate the grid with data. One of the fields that is editable is the Price cell. If I edit a Price cell and then click the Restore button, the original dataset is restored. However, if I edit a Price cell again, the ...

Make the textarea larger and bring it to the forefront when it is selected

I would like to make a textarea expand (increase its height) when it is in focus. The expanded textarea should not push the content down, but rather be displayed above other content. Currently, this is the code I am using (check out the example here): $( ...

There is no response from Ajax

I am facing an issue with my AJAX call in communication with my Rails controller. Even though the AJAX call itself seems fine, the callback function does not contain any data. Here is the AJAX request I'm making: $.ajax({ url: '/get_progres ...

Combining the jquery-UI slider functionality with the canvas rotate() method

Is there a way to rotate an image using html2canvas plugin and jQuery UI slider? I am new to programming and need some guidance on how to achieve this feature. Here is my current progress: http://jsfiddle.net/davadi/3d3wbpt7/3/ ` $("#slider").slider({ ...

Utilize alternating colors from the Material UI palette to enhance the appearance of

Can someone help me understand how to utilize the different color variants in Material UI? For instance, the theme primary color has various options like 100, 200, 300, 400, 500, and so on. How can I access these colors from within my component? I attempt ...

Set an ID value to a variable in jQuery Mobile

Hey there! I'm trying to figure out how to assign latitude and longitude values to a variable in my code so I can pass them by appending it to the url. For example, page.html?cords=[varname] The current code snippet that displays the coordinates is a ...

Is there a way to use JavaScript to add content to a document and then facilitate the download of that document?

Is there a way in JavaScript to write content to a JSON or TXT file and then download it, similar to how it is done in Python? const content = "Hello"; const link = document.createElement('a'); link.setAttribute('download', 'FileTo ...

Customizing ESLint configurations for a more productive local development environment

Let's consider an inspiring scenario: I am in the process of coding and need to troubleshoot an issue, so here is a snippet of my code: function foo() { console.log("I'm resorting to printf debugging in 2016"); } However, our build setup in ...

Retrieving HTML content using CURL

Could really use some help with my curl issue: I'm using CURL to connect to a page, then redirecting myself to another page that's only accessible when logged in. How can I retrieve the HTML code from this page? I can see the page displayed, but ...

Troubleshooting the fluid container problem in Bootstrap 3

I am currently working on a website using Bootstrap 3 framework. I have a specific section where I need to have two fluid containers placed side by side, each with different background colors. One of these containers should also include a background image ...

The hover effect in CSS brings life to list items when filled with content

I am attempting to create an animation for an <li> element that gives the illusion of a fill effect moving from left to right when hovered over. This is my current progress: ul { list-style-type: none; } .hoverTest { float: left; margin-right: 1 ...