Activating Email Subscription Form by Clicking on Icon Image

I'm attempting to include an email submission form box that appears when users click on a small envelope icon located at the top right corner of my page. However, I've encountered some difficulty as it either shows up in the midst of other icons or doesn't show up at all. Ideally, I would like for it to display just below the row of icons (please refer to the image attached). As someone who is new to this, I greatly appreciate your patience :)

Below is the HTML code (the li element is enclosed within ul and includes three other icons):

<li>
<div class="email-form"><img src="<?php echo $site_url;?>img/nav/emailicon.png?v=2" alt="E-mail Sign Up" width="23" height="23" id="email-icon" style="display: inline;"/><form class="email-form" action="subscribelink" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" target="_blank" style="display: none;"><fieldset><input type="text" name="EMAIL" value="YOUR EMAIL ADDRESS" /> <input type="submit" value="Submit" />   </div>
<div class="email-response" style="display: none;">Thank You</p></fieldset></form>   </li>
</div>
</a>

The CSS:

nav.email-form{ display:none; }

And the JavaScript:

$(function(){
$('.email-icon').on('click', function(e){
    e.preventDefault();
    $(this).next('.email-form').show();
});
});

Answer №1

To position your form container, you can use absolute or fixed positioning. Here's an example:

.email-form form {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
}

You can then use simple JavaScript to toggle it:

$('#email-icon').click(function() {
    $('#mc-embedded-subscribe-form').show();
});

Check out the demo here: http://jsfiddle.net/2RCw4/

I suggest avoiding methods like .next() because they may stop working if the markup changes.

Answer №2

My opinion aligns with dfsq's, however, I suggest using the jQuery method .fadeToggle() instead of relying on .click() and .show(). This way, it ensures that if you want to show something, you can easily hide it as well.

$('#email-icon').click(function() {
   $('#mc-embedded-subscribe-form').fadeToggle();
});

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

Tips for achieving a background animation similar to the one shown on this page

Check out this link: danielcoding.me/resume/#contact I am interested in this animation: screenshot I tried inspecting element on the page, but couldn't find any background images. How can I create this animation? Is it achieved through JavaScript or ...

NodeJS async function returning a value of undefined

Hi there! I'm currently diving into the world of async functions and I seem to be running into a bit of trouble. When I use "Resolve, Reject" with Promises, everything works smoothly. However, when I attempt to implement async instead of a new Promise ...

The content in the flex box item with horizontal scroll is overflowing beyond its boundaries

I am working with a flex box container that contains two child elements: a left side and a right side. I want the right side item to have a horizontal scrollbar in order to fit its content. .container { display: flex; overflow: hidden; height: 300 ...

Eliminate the error notification on the login page if it corresponds to the input

I am facing an issue with my login page and the API for password validation. Even when the password matches, an error message is still being displayed. This is because I am looping through the data and need to break the loop once a match is found. How can ...

Jquery Mobile - Unstyled Popup

I have a question regarding popups. From what I've read, popups should be on the same page as the anchor that triggers them. But how does it work with multipage websites? The problem I'm encountering is that while the popup appears, the elements ...

Access a designated div within an iframe following the submission of a form

I wanted to discuss my current setup... Currently, I have two pages in the project - index.html and cart.html. The issue arises when a form on index.html is submitted because it loads cart.html into a pop-up iframe. In this case, the entire cart.html page ...

Having trouble installing Angular 4 with npm?

After installing Angular, I encountered an error when trying to use the command line "ng -v". Please refer to the attached jpeg file. My node version is 6.10.3. Does anyone have a solution? https://i.sstatic.net/ZQ69k.png ...

Using Typescript does not generate any errors when indexing an object with brackets

One interesting thing I've noticed about TypeScript is that it allows me to use bracket notation to access an object via index, even when it only has keys. For example: interface testObject { name: string; id: number; } let first: testObject ...

Prevent the loading of multiple jQuery versions

Currently on Yii 2.0.9, I am encountering an issue with conflicting jquery versions. The framework loads jquery 2.2.4 without any issues, but the krajee extensions are introducing jquery 1.7.2 which I do not prefer. Is there a way to modify my AppAssets ...

At what point in the lifecycle of my component am I able to begin using this.$refs?

Exploring ways to integrate HTML5 audio events while initializing a Vue.js component that consists of a single file: <template> <audio ref="player" v-bind:src="activeStationUrl" v-if="activeStationUrl" controls autoplay></audio> < ...

"Looping through each item in a list using Angular

I have a setup for an HTTP request that will return the list of products once all promises are fulfilled. My objective is to initially set the opacity of these products to 0, and then use a forEach loop to add a class that sets their opacity to 1. While ...

When attempting to parse a JSON file with jQuery, a 304 Not Modified error message appears

$(document).ready(function() { console.log(getJ()); function getJ() { $.getJSON('json.json', function(data) { $.each(data, function(key, val) { console.log(key) ...

Troubleshooting issue with applying Select2 class dynamically with JavaScript

When developing my web application, I faced a challenge of dynamically adding new rows to a table using JavaScript. The row contains a <select> element which loads data from the ViewBag for its <options>. Additionally, I wanted to apply the Sel ...

Switch between class and slider photos

I am currently having an issue toggling the class. Here is the code I am working with: http://jsfiddle.net/h1x52v5b/2/ The problem arises when trying to remove a class from the first child of Ul. I initially set it up like this: var len=titles.length, ...

Adjust the background color of the date and time selection tool

Trying to customize the background of a datetime picker created using jquery.pttimeselect.js. Despite linking the correct css file (jquery.pttimeselect.css), I am unable to change the background color. Any suggestions on how to successfully modify the ba ...

Modify the image inside a div when hovering

How can I create a product card that displays thumbnails of images when hovered over, and changes the main image to the thumbnail image? My current challenge is getting this functionality to work individually for each card on an e-commerce site. Currently, ...

Issue with using bind(this) in ajax success function was encountered

In my development process, I utilize both react and jQuery. Below is a snippet of the code in question. Prior to mounting the react component, an ajax request is made to determine if the user is logged in. The intention is for the state to be set when a ...

Using the power of ReactJS, efficiently make an axios request in the

After familiarizing myself with Reactjs, I came across an interesting concept called componentDidUpdate(). This method is invoked immediately after updating occurs, but it is not called for the initial render. In one of my components, there's a metho ...

The event is not functioning properly with jquery

<div id="form"> <form action=""> <input type="button" id="sub"/> </form> </div> Upon clicking the submit button, the content will be dynamically changed using jQuery. Here is the jQuery code: $(document).ready(function() { ...

Executing a TypeORM query with a distinct clause that ignores case sensitivity

I am attempting to construct a TypeORM query builder that pulls data from a postgresql database to retrieve all unique names. Here is how my query currently looks: names = await this._context.manager .getRepository(Names) .createQueryBuilde ...