Encountering an error while utilizing the Tether JavaScript Library

I'm currently in the process of developing a new website and I'd like to add a footer within a container div situated at the bottom.

After some research, I came across a JavaScript library known as Tether (), but I've run into issues with its implementation.

Here is the HTML code I've been working with:

<html>
    <head>
        <title>Bug Reporting</title>
        <link href="StyleSheet.css" type="text/css" rel="stylesheet" />
        <script src="includes/jquery.js"></script>
        <script src="includes/tether/tether.js"></script>
        <script>
            $(document).ready(function()
            {
                new Tether({
                    element: '.footer',
                    target: '.container',
                    attachment: 'top left',
                    targetAttachment: 'bottom left'
                });
            });
        </script>
    </head>
    <body>
        <div class="container">
            <header>
                This is the body
            </header>

            <div id="content">
                This is the content<br />
            </div>

            <div class="footer1">
                This is the footer
            </div>
        </div>
    </body>
</html>

Below you'll find my StyleSheet code:

html, body
{
    font-family: arial;
    margin: 0;
    padding: 0;
}

header
{
    background-color: red;
    width: 100%;
    height: 80px;
}

.container
{
    background-color: yellow;
    height: calc(100% - 80px);
    width: 100%;
}

#content
{
    background-color: blue;
    width: 1024px;
    margin-left: auto;
    margin-right: auto;
    height: auto;
}

.footer1
{
    position: absolute;
    background-color: green;
    width: 100%;
    height: 80px;
}

The issue I'm facing is that upon loading the page, an exception occurs within the tether library:

Uncaught TypeError: Cannot read property 'classList' of null

I would greatly appreciate any assistance or guidance you can offer on this matter.

Answer №1

Tether's settings specify that the element and target should be a DOM or jQuery element (loosely defined), not a string.

To use Tether properly, you must provide a jQuery object like this:

$(document).ready(function() {
    new Tether({
        element: $('.footer'),
        target: $('.container'),
        attachment: 'top left',
        targetAttachment: 'bottom left'
    });
});

Ensure that the elements are present on the page when initializing your Tether instance.

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

Chrome's spinner fails to appear when performing a synchronous ajax request in IE9

While implementing an ajax request, I want my users to see a spinner for visual feedback. Surprisingly, the spinner works flawlessly on Firefox 13, but fails to function on Chrome and IE9 even though the ajax request takes approximately 1.2 seconds to comp ...

Angular directive does not focus on the text box

I've been working on creating text boxes using a directive and I want only the first text box to be in focus. To achieve this, I am utilizing another directive for focus control. Below is my script: <script> angular.module('MyApp',[]) ...

Creating a Full Height Layout with Two Columns Using Bootstrap 4

Looking for a solution similar to the one discussed in this thread. I'm struggling to figure out how to achieve the layout shown below using Bootstrap 4. The key requirement is that col 1, col 2, and col 3 must stretch to the bottom of their respecti ...

Creating a button with multiple background gradients using CSS

When working on a button element that already boasts a gradient effect, my aim was to integrate a small play image directly in the center. However, achieving this without compromising the current layout and ensuring compatibility across various browsers pr ...

How to use Jquery to set the selected item in a dropdown menu

I'm facing an issue with my drop-down menu - whenever I select an option, the page redirects to a different URL. What I want is for the selected item in the drop-down menu to become the new page. Below is the code I have: HTML: <select class="Mob ...

How can I eliminate padding from events in FullCalendar's timeGrid view?

Is there a way to remove the padding from an event when the calendar is in 'timegridview'? Users are taking advantage of the empty space created, allowing them to bypass a blocked time slot. I currently have it set so that clicking on an event d ...

What is the best way to include a class multiple times in a render method?

I'm currently working on a React project and have the following code snippet. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>JS Bin</t ...

JavaScript error: Trying to access property 'startsWith' of an undefined value - discord bot

I have limited knowledge of javascript, being more experienced in Java. I wanted to create a simple Discord bot that could send messages randomly at different times. After piecing together code from multiple tutorials, here is what I currently have: var D ...

`` `Are you unsure when to use arrayobject instead of objectarray in JavaScript?

I'm struggling to understand when it's best to declare an object inside an array or an array inside an object. Object inside an array var users = [{'Name': 'Alex', 'Value': 2}] Array inside an object var user_dat ...

Turn off the ripple effect for this element

I am looking to turn off the ripple effect on an ion-chip component, which activates when clicked: <ion-chip> <ion-label>Hey</ion-label> </ion-chip> Is there a way to accomplish this? ...

Differences between Tags and Elements in HTML5

Could someone provide a detailed explanation of the distinctions between tags and elements in HTML5? I am curious about this topic because I have noticed a lot of confusion regarding the terminology online, with the terms being used interchangeably even o ...

"Encountering an issue with AngularJS where the selected ng-model value is

I'm utilizing plain options for the select tag because I only need to display a few options when they meet a certain condition. In order to perform other operations, I require the value of the selected dropdown in the controller. However, the issue is ...

Comparing WebSockets and XHR for transmitting data

Looking to optimize the architecture of a web application using Node.js, the goal is to efficiently send medium-sized files to the client from a gallery. Each gallery item should be delivered to the user as quickly as possible in binary form. The file size ...

Is it achievable to use the Jquery :after selector?

I am facing an issue with a menu script in my HTML code that looks like this: <ul class="cbp-tm-submenu" style="left: 50px;"> <li><a href="#" class="cbp-tm-icon-screen">Sorrel desert</a></li> <li><a href="#" ...

Preloading resources using the <link> tag with "preload" attribute as "script" is different from simply including a <script> tag with a "src" attribute

Can you explain the distinction between these two elements? <link rel="preload" as="script" href=".."> and <script src="..." /> Do you think rel="preload" is necessary in the first scenario? ...

One way to incorporate if / else if statements into a function within a Class component is by using conditional logic in React alongside Node and Express

I'm looking to refactor my code and extract the if/else if statements for error handling out of the component. How can I export this logic to another file and then import it back into my main component? Here's an example of the code: // PASSWOR ...

A step-by-step guide on displaying log files using NanoHTTPD

I have developed a Java desktop application that can receive HTTP requests using the embedded NanoHTTPD web server from https://github.com/NanoHttpd/nanohttpd. Once an HTTP request is received, my application performs certain tasks and logs the activity to ...

Responsive design can sometimes cause CSS float layouts to appear unbalanced

I have designed a grid with dimensions of "3x2" using media queries. The grid appears correctly on desktop, but when viewed on mobile it changes to a "2x3" grid. However, the issue arises when there is varying text length in each grid item. To prevent item ...

JavaScript function that shows the name of an individual extracted from a specific file

Hey there, currently I'm diving into a javascript tutorial and exploring ways to display a person's name along with their birthday on this historical day. <script type="text/javascript"> document.write("Today is <br/&g ...

Show information in a horizontal layout, but switch to a stacked arrangement if the screen is too narrow

Is there an optimal way to arrange content side by side when the width allows, like this: [content] [content] [content] [content] If the screen becomes too small, should the content automatically stack like this: [content] [content] [content] I am ...