Toggle the input box by clicking the button

How do I show or hide the input box (blue square) when I click the search button (red square)? Link Image

I attempted to create the transition in CSS and also experimented with JavaScript, but the JavaScript part confused me.

Here is what I tried:

$("#Hide").click(function() {
    $(".buttontoggle").hide("blind");
});
* {
  padding: 0;
  margin: 0;
}

html {
  background-image: url(../Images/background.jp);
  background-repeat: no-repeat;
  background-attachment: fixed;
  font-family: 15px/1.5 'Arial', 'Helvetica', 'sans-serif', 'Montserrat';
}

body {
  height: 2000px;
}

.container {
  border: 2px solid;
  width: 1164px;
  height: 1600px;
  margin: 177px 350px 0px 371px;
  overflow: hidden;
  background-color: #0A081E;
}

// More CSS code...

<body>
  <header>
    <div class="nav-container">
      <a href="Default.aspx" id="Logo">
      </a>
      <nav>
        <ul>
          <li class="buttontoggle"> <a href="#">New Release</a> </li>
          <li class="buttontoggle"> <a href="#">Others</a> </li>
          <li class="buttontoggle"> <a href="#">Top</a> </li>
          <li class="buttontoggle"> <a href="#">Contact</a> </li>
          // More HTML code...
          <li><i class="fa fa-search" id="Hide"></i></li>

          <div class="vl"></div>
          // More HTML code...
        </ul>
      </nav>
    </div>
  </header>

  <body>

I have tried several different approaches and also experimented with using the webkit transition in CSS, but it did not achieve the desired effect. Here are the images of what I have tried: https://i.sstatic.net/4kMzr.png and https://i.sstatic.net/rpkK8.png

I apologize for my limited English proficiency, I hope you can still understand my message.

Edit: You can try live editing here: WebPage

Answer №1

To enhance the user experience, consider using toggle instead of hide in the following code snippet:

$("#Hide").click(function() {
    $(".searchbox").toggle("blind");
});

Also, ensure that you have included jQuery in your HTML file. If not, you can quickly test your code by adding the following line:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

Similarly, if you are using font-awesome icons, make sure to include the necessary CSS file:

<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">

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

How about incorporating two subtly tilted SVGs for a creative twist on navigation backgrounds?

I am in the process of designing the navigation menu for my website and I have a specific vision in mind. I want to create a unique background using two rectangular SVGs that are slightly rotated off axis and overlapping each other, with their edges extend ...

Sending a JavaScript string to a PHP script from a Chrome extension content script

I am currently developing a chrome extension that is designed to extract text data from specific websites when I visit them, and then store this data in a SQL database. The JavaScript code for data extraction is functioning correctly and is able to capture ...

modal failing to populate values within control elements in modal

Encountering an issue where the code is calling a Modal, but upon loading it fails to populate the controls with values sent into the JavaScript. No errors are thrown, yet all controls remain empty. As a newcomer to AJAX and JavaScript, I suspect there mig ...

Issue encountered: Incompatibility between Mongoose Populate and Array.push()

After reading a different post addressing the same issue, I still couldn't figure out how to implement the solution into my own scenario. The discussion revolved around the topic of node js Array.push() not working using mongoose. In my Mongoose asyn ...

When an express pre-remove signal initiates another pre-remove action during the removal process

Imagine having 4 different models structured like this: ┌────────────┐ ┌────────────┐ │ User │ │ Goal │ ├────────────┤ 1 ├───── ...

What is the best way to retrieve the second element based on its position using a class name in Jquery?

DisablePaginationButton("first"); The statement above successfully disables the first element that is fetched. DisablePaginationButton("second"); ===> not functioning function DisablePaginationButton(position) { $(".pagination a:" + position).ad ...

Change not accepted

I am a beginner in Angular and still grappling with the fundamentals. On my menu, I have a cart icon with an initial value of 0 upon first load. In my product list, each product has an 'AddToCart' button. What I aim to achieve is- I want to dy ...

What sets apart `Object.merge(...)` from `Object.append(...)` in MooTools?

This question may seem simple at first glance, but upon further inspection, the MooTools documentation for the 'append' and 'merge' methods appears to be identical. Here is the code snippet provided in the documentation: var firstObj ...

Efficiently managing multiple database updates with PHP and JQuery

Having trouble processing multiple mySQL updates simultaneously? I have 4 select/option boxes fetching data from a db table and I want to update the database onChange using JQuery. It's working with one select module, but adding more causes issues. Th ...

How can you conceal the navigation and footer components on a 404 page using Next.js?

import Footer from "./Footer"; import Navigation from "./Navigation"; import { useRouter } from "next/router"; function CustomLayout({ children }) { const router = useRouter(); return ( <> {router.pathname ...

Unable to update div CSS using button click functionality

I have been working on this HTML/CSS code and I am trying to change the style of a div using a JavaScript button click event so that the div becomes visible and clickable. However, despite my efforts, it doesn't seem to be working as expected. Whenev ...

What is the most efficient way to transfer a string to a python program using ajax and retrieve a string in return?

I'm experiencing a problem with my ajax request where I am sending an object to a python program using JSON: $.ajax({ url: "http://localhost/cgi-bin/python.cgi", type: "POST", data: JSON.stringify(myobject), dataType: ...

Encountering a VueJS error when trying to locate a module while using a JSON file

I've been tasked with finding a solution to dynamically import pages within vuejs projects that are being built with a CLI tool by my team. I initially attempted to use functions as a string ("() => import(...)") and then evaluate that string, but ...

Ensure the HTML table's <td> cell width automatically adjusts to accommodate the image, regardless of its dimensions

Has anyone encountered a strange issue while building an HTML table for an HTML email? Whenever I insert an image into a <td>, it causes the cell to expand to its maximum width, affecting all the columns to the right by resizing them to their minimum ...

Generating interactive child posts for a specialized post type in WordPress

I am currently in the process of planning a simple plugin and am searching for ideas on how to add subposts (child) for posts in WordPress directly on the post creation page. I would like to incorporate a form with two fields, title and content, and have ...

The background color spills outside the column when using 100% width

Bootstrap 5 is being used, and two columns have been created on the page. The current output looks like this: https://i.stack.imgur.com/P6oZs.png Now, there's a need to display an orange color from end to end of the left column. To achieve this, h- ...

Ways to update a component when the value of a Promise is altered

I am struggling with Vue component re-rendering due to a problem related to consuming data from a Promise. The data is fetched and stored under the specific property chain (visualData.layout.cube...), where I assign values to DATA properties (such as label ...

When attempting to use focusin/focusout, I encountered the following error: Uncaught TypeError - The property 'addEventListener' cannot be read from null

When attempting to utilize the DOM events focusin/focusout, I encountered an error: Uncaught TypeError: Cannot read property 'addEventListener' of null. The issue seems to be originating from main.js at lines 18 and 40. I am using Chrome as my b ...

Exploring jasmine testing with ajax requests

I've been working on writing Jasmine unit tests for a JavaScript file that includes an Ajax call. I'm unsure how to properly test the 'Success' function using Jasmine. Here's a snippet of the code: function getGroups(){ var defe ...

Trouble with HTML img srcset functionality?

I'm currently working on implementing responsive images, and while everything seems to be functioning correctly in the latest version of Firefox, I'm encountering issues with Safari and Chrome. <img src="/images/pages/arrivals/02_exterio ...