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

Initiate Unity through C++ (separating functions and display)

Running Unity on Linux, I have a C++ setup with controllers and physics for object transformations. Currently utilizing Qt and OpenGL for display purposes. Considering transitioning from Qt and OpenGL to Unity for a more robust solution. Is it possible t ...

Is there a way to access the chat source code without relying on selenium for assistance?

My dilemma lies in wanting to extract the user's id information from the chat interface. The specific section I am interested in within the chat area appears as follows... <div id="chat_area" class="chat_area" style="will- ...

Flaw in Basic Function Logic Using HTML, JavaScript, and CSS

Need some help with the function onBall3Click1 (code is at the bottom). The ball should act like a lightbulb: ON - turn YELLOW, OFF - turn GRAY. I've been trying to figure out the logic behind it for so long and can't seem to find the issue... ...

Having trouble retrieving object values from the request body during a POST request in [Node.js, MySQL]

I am currently developing a management system and working on creating POST requests for the API to add a new city to the database. However, I am facing an issue where instead of receiving the correct values from the request's body, I am getting "undef ...

There seems to be a glitch with Ajax functionality, causing issues with PHP's ability to successfully

I have been utilizing a Jquery array to retrieve variables from dynamic input forms. Despite successfully grouping and outputting the arrays into console.log, I encountered an issue where no data was being inserted into the multiple table database itself. ...

Is there a way for me to determine when the modal animation has completed?

I'm currently using the modal feature in twitter-bootstrap and I am curious about how long it takes for the modal to appear before triggering an alert. To better illustrate my point, you can check out this example: HTML <button id="mod" class="b ...

Scrolling automatically

I'm experimenting with creating a typing effect using JavaScript and the typed.js library, found here: My approach involves using a div as a container. However, I've encountered an issue - when the text reaches the height of the div, scroll bars ...

Modifying an image or audio using document.getElementByID("...").src=x+".png" is not effective

I'm having trouble figuring out why it's not working. I've searched online and here, but all I could find were tutorials that didn't include the variable or questions that were too specific. Can someone help me with this? <html> ...

Guide to establishing intricate conditions for TypeORM insertion

When attempting to insert data based on a specific condition, such as if shopId = "shopA", I want to include the shopdetail. In order to achieve this, I have implemented the following business logic, which is somewhat complex. Is there a more ef ...

Integrate a character key feature to cycle through options in a customized Vue select component

In my Vue/Nuxt.js project, I have implemented a custom select component with arrow key functionality for scrolling through options and selecting with the enter key. Now, I am trying to add "jump key" functionality where pressing a character key will jump t ...

Why does box-shadow only display on the bottom border and not the right and bottom border?

I want to add a shadow effect on the bottom and right sides of a specific div. #navigation-and-slideshow { overflow: hidden; background-color: #fff; padding: 10px 1%; box-shadow: 2px 2px 5px #222; } However, I am only seeing the shadow ef ...

rectifying file extension hyperlinks

While designing a webpage on my MacBook's local server, I unintentionally omitted the ".css" file extension in the href attribute of a link to my locally stored stylesheet. The mistake went unnoticed until I transferred my files to an externally hoste ...

What is the optimal method for iterating through every element in a string array?

Within my code, I am dealing with an array named var mya = ["someval1", "someotherval1", "someval2", "someval3"];. The goal is to have a function that receives an object with a property set to one of these values. Instead of simply iterating over the arra ...

Cannot access PDF files on Android Chrome

I'm using a responsive bootstrap application and encountering an error when trying to open a PDF on mobile. I can open the PDF from my iPhone, but when trying to do so on Android Chrome, I receive a "media not supported exception" message. The applic ...

Switch Focus and Collapse Submenus upon Menu Click in Recursive React Menu

I've created a dynamic menu system in React using Material-UI that supports recursion for submenus. I'm aiming to implement the following features: 1. When a menu item is clicked, all other open submenus should close and focus on the clicked men ...

How can we eliminate the 'www' in a URL using NodeJS and Express?

What is the best way to eliminate the 'www' in a URL using NodeJS + Express? For instance, when a client connects to , how can we automatically redirect them to without the 'www'? ...

Troubleshooting Vue.js rendering problems on Safari_BROWSER

I'm encountering a strange issue with my portfolio website, which is built using Vue and Laravel. The problem arises specifically in Safari - the project thumbnails don't display until the browser window is resized. Here's the relevant code ...

Leveraging ACE in conjunction with WT

UPDATE 3 Here is the finalized working code below. Remember to use ace.js from the src folder, as it will not work from the libs directory. You need the pre-packaged version from their site. WText *editor = new WText(root()); editor->setText("function( ...

Algorithm for Filling Tiles in a Gaming Environment

Background: In my current project, I'm developing a unique tile-based game in Javascript. The game involves a character who can freely move around the map without taking diagonal paths - only left, right, up, or down movements are allowed. As the cha ...

Steps for using Jquery to establish PHP session through a checkbox implementation

I am in the process of setting up a PHP session whenever a checkbox is selected. I have successfully implemented this for individual checkboxes using the code below: onchange="$.get(\'set_item.php?stockID='.$row[stockID].'&push=&bs ...