Displaying a JQuery notification when hovering over a link

I am having trouble getting an alert to pop up when I hover over a hyperlink using JQuery and Javascript. The hyperlink is inside an anchor within the main section of the HTML. Any assistance would be much appreciated.

Here is my current code snippet:

<!DOCTYPE html>
<html lang="en">

<head>
    <title>JavaJam Coffee House Music</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="javajam.css" rel="stylesheet">
    <!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js">
</script>
<![endif]-->
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
    </script>
    <script>
        $(document).ready(function () {
            $('main a').hover(function () {
                alert("Concerts sell out quickly so act fast!");
            }};

    </script>

</head>

<body>
    <div id="wrapper">
        <header>
            <h1>JavaJam Coffee House</h1>
        </header>
        <nav>
            <ul>
                <li><a href="index.html">Home</a>;</li>
                <li><a href="menu.html">Menu</a>;</li>
                <li><a href="music.html">Music</a>;</li>
                <li><a href="jobs.html">Jobs</a>;</li>

            </ul>
        </nav>
        <main>
            <div id="heroguitar">
            </div>
            <h2>Music at JavaJam</h2>
            <p>The first Friday night each month at JavaJam is a special night. Join us from 8 pm to
                11 pm for some <a href="#">music you won't want to miss!</a></p>
            <h4>January</h4>
            <div class="details">
                <a href="melanie.jpg"><img src="melaniethumb.jpg" height="80" width="80" alt="Melanie Morris" class="floatleft"></a>
                Melanie Morris entertains with her melodic folk style.
            </div>
            <h4> February</h4>
            <div class="details">
                <a href="greg.jpg"><img src="gregthumb.jpg" height="80" width="80" alt="Melanie Morris" class="floatleft"></a>
                Tahoe Greg is back from his tour. New songs. New Stories.
            </div>
        </main>
        <br>
        <footer>
            Copyright &copy; 2016 JavaJam Coffee House<br>
            <a href="#"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a8cadacddcdce8cac9c6c1cbc086cbc7c5">[email protected]</a></a>
        </footer>

    </div>
</body>

</html>

Answer №1

It appears that the issue lies with some bracketing errors in your JavaScript code. Here is the corrected version:

$(document).ready(function(){
    $('main a').hover(function(){
        alert("Concerts sell out quickly so act fast!");
    });
})

Remember to utilize F12 (developer tools) to identify and fix these types of errors more efficiently.

Answer №2

The hover() function was not properly closed. The correct syntax after alert(...) should be:

    })
  });

Ensure to include the closing parentheses within the braces.

Answer №3

Your reasoning is spot on, however, there appears to be a error - the problem lies in the fact that you did not properly close the braces after your alert().

The correct format should be as follows:

$(document).ready(function () {
    $('main a').hover(function () {
        alert("Concerts sell out quickly so act fast!");
    });    // correction made
});        // adjustment implemented

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

Having difficulties fetching the post content in Wordpress using AJAX

I am currently working on ajaxifying my Wordpress theme by utilizing the ajax-in-WordPress method as detailed on this page. However, I am encountering an issue when attempting to retrieve the content of a post using get_the_content function within function ...

"Troubleshooting: Why isn't my Bootstrap alert displaying properly after implementing Ajax

I'm currently working on validating a form using ajax. I have utilized bootstrap's alert alert-danger and alert alert-success classes to enhance the UI, but upon return, it is only displaying as plain HTML without the desired appearance. Can some ...

When the app loads in AngularJS, make sure to call the jQuery plugin. Additionally, remember to call

In my AngularJS app, I have a need to call the following code: $('.nano').nanoScroller({ alwaysVisible: true }); This should be executed when the application loads and also when the state changes. In traditional non-angular applications, I wou ...

Performing Vue CLI Global Upgrade

Struggling to create a new Vue.js project using the Vue CLI service, I encountered an error. With @vue/cli-service 3.0.0-beta.7 installed (confirmed by running vue -V), attempting to start a new project triggered the following error: ...

Display only the highest image in the picture carousel using Jquery

My goal is to create a simple image slider using HTML, CSS, and Jquery. However, when I try to move it left by 750px, only the topmost image moves and the rest of the images are not displayed. It seems like all the images are moving at once instead of jus ...

The most effective method for acquiring an object through inheritance

I'm seeking advice on the best practice for adding behavior to an object received as a JSON object. I have REST services that allow me to define a sort of state machine. The API defines a /sessions resources. When creating a session via POST /sessio ...

Is it possible to generate an array of strings from the keys of a type or interface?

Imagine a scenario where we have a type or interface defined as NumberLookupCriteria: type NumberLookupCriteria = { dialCode: string; phoneNumber: string; } or interface NumberLookupCriteria { dialCode: string; phoneNumber: string; } Is there a w ...

How long does jQuery animation last until completion?

Within my project, I am utilizing the animationComplete function from the jQuery mobile library. You can find this function at The animation in my project involves a sequence of objects with various tasks to be executed at each point of the animation. The ...

Tips for storing the output of a script URL in a JavaScript variable

I am currently facing an issue with running a script in the 'head' element of a webpage. The script makes an API call to a specific URL and retrieves results in the form of a JavaScript array. However, I am encountering difficulty because the API ...

Identify all elements that possess a specific attribute with a precise value in jQuery, and return either true or false

I'm having a slight issue with jQuery. Below is the code in question: if ($("select[rendelo='" + rendelo + "'][nap='" + nap + "'][napszak='" + napszak + "']").val() == 0) { alert('sth'); ...

Information within specified dates shows all leaders

Looking to filter data based on Start Date, End Date, and HeadName. The current search query successfully filters between dates but does not properly filter the HeadName column, displaying all results instead. Sno HeadName Date Amount BillNo BillD ...

Leverage the power of DOMXPath in combination with the query function

Here is a snippet of HTML code to work with: <ul id="tree"> <li> <a href="">first</a> <ul> <li><a href="">subfirst</a></li> <li><a href=""> ...

Handling Website Downtime with PHP Simple HTML DOM Parser

I have been extracting data from a government website for health updates in Turkey. However, if the site experiences downtime or fails to load, my own website stops displaying any content after fetching and parsing the news. Is there a way to optimize th ...

What is the best method for displaying plain text using the br tag?

My component looks like this: class News extends Component { state = { isSimple: this.props.isSimple } render() { return ( <div> <div className="extended">extended</div> simple text </div&g ...

How can we implement :focus-within styling on Material-UI Select when the input is clicked?

I am currently implementing a Select component inside a div element: <div className="custom-filter custom-filter-data"> <DateRangeIcon className="search-icon"/> <FormControl variant='standard& ...

jQuery's slide toggle function is limited to toggling the visibility of just one section at

Welcome to my first post! As a newbie in web development, I have just started my first project. While I feel comfortable with HTML and CSS, jQuery is proving to be a bit challenging for me. In the head section of my intranet page, I have the following cod ...

Does anyone know of a CSS/JavaScript framework that can be used to replicate the look and functionality of the iOS home

I'm wondering if there is a CSS/JavaScript framework that replicates the layout of an iOS home screen. I want to create a kiosk website with a grid layout similar to Android/iOS where apps can be displayed as icons. ...

What is the best way to customize the look of the v-calendar component in Vue.js?

I've recently started a project that involves Vue.js, and I needed to create a datepicker for it. After some research, I opted to utilize the v-calendar package. The implementation of the component went smoothly and functioned as expected right out o ...

Animation in CSS Appears Jumpy in Chrome

For some reason, the text inside a moving div (which is transitioning using CSS) seems to jitter and shake in Chrome. However, this issue does not occur in Firefox, where the movement is very smooth and achieves the desired effect. #hidexpert { display: b ...

Animate a Bootstrap icon displaying an unattractive border

When I click on a static Bootstrap glyphicon, I want to replace it with an animated one. My challenge is that if I use the replaceWith() function to completely swap out the icon, it looks great. However, if I try to just switch the classes using removeClas ...