Display a div with a link button when hovering over an image

Currently, I'm attempting to display a link button within a div that will redirect the user to a specified link upon clicking. Unfortunately, my current implementation is not functioning as expected. I have provided the code below for reference - please review it and point out any mistakes or errors you may identify.


<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style>
        div.out { width:40%; height:120px; margin:0 15px; background-color:#D6EDFC; float:left; }
        div.in { width:60%; height:60%; background-color:#FFCC00; margin:10px auto; }
        p { line-height:1em; margin:0; padding:0; }
    </style>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
    <form id="form1" runat="server">

        <img src="Images/orderedList2.png" id="actionImage" />
        <div class="out overout">
            <span>move your mouse</span>
            <div class="in">
                <p>The function bigImg() is triggered when the user moves the mouse pointer over the image.</p>
                <a href="www.google.com" id="A1" class="target">www.google.com</a>
            </div>
        </div>
        <div class="out enterleave">
            <span>move your mouse</span>
            <div class="in">
                <p>The function bigImg() is triggered when the user moves the mouse pointer over the image.</p>
                <a href="www.google.com" id="url" class="target">www.google.com</a>
            </div>
        </div>
        
        <script type="text/javascript">
            $('#actionImage').mouseover(function (e) {
                $("div.enterleave").show();
                $('#actionImage').mouseout(function () {
                    $("div.enterleave").hide();
                });
            });

            $("div.enterleave").mouseenter(function () {
                $(this).show();
            }).mouseleave(function () {
                $(this).hide();
            });
        </script>

    </form>
</body>
</html>

Answer №1

Make sure to include the protocol in the address when specifying a URL. Update the href parameter in your anchor tag like this:

<a href="http://www.google.com" id="A1" class="target">www.google.com</a>
<a href="http://www.google.com" id="url" class="target">www.google.com</a>

If you want to learn more about protocols, check out the following resource:

Here are some common protocols and their associated port numbers:

Port Number - Service
80 - HTTP
21 - FTP 110 - POP3
25 - SMTP
23 - Telnet

Answer №2

While I can't speak to the specifics of your JavaScript setup, one fundamental mistake in your current code is that your links are missing the "http://" prefix.

<a href="http://www.example.com">Example</a>

Answer №3

<a href="www.google.com" id="url" class="target">www.google.com</a>

update the link to

<a href="http://www.google.com" id="url" class="target">www.google.com</a>

as external links should begin with http or Https for proper functionality

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

Is there a way to have the user input data into a Firebase database directly from a Vue.js component?

Any assistance for a beginner like me would be greatly appreciated. I am currently working with vuejs and firebase to write data into the database from a vue component. I have successfully implemented authentication and writing functionality, but now I wan ...

Tips for positioning an inline label and input field in an Angular application using CSS and HTML: How to align the label to the left and the input

I'm currently developing an Angular form with multiple label-input field combinations. I have managed to style the labels and input fields with inline block so that they appear on the same row. However, I am facing a challenge in aligning the label to ...

What unique capabilities does canvas offer that are not available with SVG?

Currently tackling a project that requires choosing between SVG and Canvas. After extensive research, it seems like SVG outperforms Canvas in many aspects. Is there anything that Canvas can do but SVG cannot? I'd love to hear your insights. ...

Using JQuery to Manipulate Checkboxes

Recently, I've been facing an issue with JQuery and Checkboxes. Let me provide you with an example: <input type="checkbox" name="guest" value="1" /> <input type="checkbox" name="guest" value="2" /> <input type="checkbox" name="guest" v ...

Troubleshooting: Issue with Updating Views in Angular JS

I've been attempting to change the view from the controller, but it's just not working properly. app.js var app = angular.module('vla', ['ngRoute']); app.config(function ($routeProvider){ $routeProvider ...

Place text directly below the images for proper alignment

In my current rails app, I am working on the contributors page. Each member's name should be displayed centered beneath their respective images. Any assistance with this would be greatly appreciated. Below is a snippet from my member.html.erb file ...

Restarting the timer in JavaScript

How can I reset the countdown timer every time a user types into an input field? I tried using clearTimeout but it doesn't seem to work. Can anyone help me with my existing code instead of providing new code? DEMO: http://jsfiddle.net/qySNq/ Html: ...

Top method for generating a complete object using information from various APIs

I am currently working on an app that consists of a comprehensive form with multiple dropdowns. These dropdowns need to be populated with data from the database. The app utilizes a server with Express, functioning as a proxy: I make calls to it from the fr ...

Protractor Encounters Error When Assigning Variable

var itemStatus = element(by.model('item.statusId')).getText(); This issue is causing Protractor to raise an error: Uncaught exception: Error while waiting for Protractor to sync with the page: "Angular could not be found on the window" Pro ...

Issues with the menu pop-up functionality arise when utilizing the CSS class .active

When I have this code, the ".active" function doesn't work when clicked. However, if I change the div class from "top-menu-popup" to "top-menu-popup active" when opening the page, the menu is already activated. <div class="top-menu-popup"> ...

Customize numbers in JavaScript with a Unity-inspired design changer

I am currently working on implementing a number input feature that allows users to adjust values by clicking and holding the mouse button while moving the cursor left and right, similar to Unity's editor number adjuster: https://youtu.be/uY9PAcNMu8s?t ...

Delegating events with .on('click') and using the CSS negation selector :not()

Struggling to implement event delegation for a dynamically added or removed class? I need to create an event for elements that are clicked, but without a specific class. Here's the code I have so far, but it doesn't seem to be working. Could it b ...

Using Javascript to Retrieve Object-Related Information from an Associative Array

I have a list of students' names along with the grades they achieved for the semester. How can I modify my JavaScript code to display the first names of students who earned an "A" grade based on the array provided? This is my current progress, but I k ...

Unable to install react-dom/test-utils using npm

I recently included two libraries in my package.json "devDependencies": { ... "react-dom/test-utils": "*", "react-test-renderer/shallow": "*" }, These were recommended by the React documentation to align with version 16 of the React ecosy ...

An issue has arisen where FormData fails to send the value of a

My current issue involves submitting a form using FormData. Interestingly, all input types are functioning as expected except for checkboxes. When the checkbox value is set to 1 or 0, Ajax fails to post it. <form id="update-form" method="PUT" enctype= ...

What is the best way to transfer variables to a different page through a pop-up window?

I'm working with a function that converts the Id of the clicked element into a variable, then opens a new window with a different page. How can I access or utilize this variable on the newly opened page? var idToWrite = []; $(function(){ $(".szl ...

Creating a multilingual website with Nextjs 13 App Router using internalization, all without the need

As I develop a web app that requires user authentication to access, I am currently using Next.js 13 with the App Route (not Pages Route). My goal is to implement internationalization without having to create sub-routes like /en, or use domains such as mywe ...

The received reply does not align with the set parameter configuration:

Encountering an issue with Angular $resource: error description Error: error:badcfg Response does not match configured parameter: Error in resource configuration for action `array`. Expected response to contain an object but got an {2} Initialization of ...

Ways to display title attributes when focused using jQuery?

Typically, title attributes in all browsers only appear when the mouse hovers over them. I am looking to also display them when users are focused on them via keyboard navigation. Unfortunately, without using JavaScript, this cannot be achieved solely throu ...

Experiencing issues with obtaining req.params.id undefined while initiating a put request

Encountering an issue while making a PUT request using Postman, as an error occurs in the VSCode terminal with the message: let product = await Product.findById(req.params.id); ^ TypeError: Cannot read property 'id' of undefined. The request ...