What steps can I take to hide my textarea after it has been clicked on?

Recently, I reached out for help on how to make my img clickable to display a textarea upon clicking. While I received the solution I needed, I now face a new challenge - figuring out how to make the textarea disappear when I click the img again. Each click on the img creates duplicate textareas and despite my efforts, I have been unable to solve this issue on my own. Can anyone offer assistance with this? Thank you in advance.

function myFunction() {
  const textArea = document.createElement("textarea");
  textArea.rows = 10
  textArea.id = "text";
  textArea.cols = 30;
  textArea.readonly = true;
  textArea.innerHTML = `I have been learning and creating web page content since 2015.  
            I'm a part-time student in Information Technology with a concentration in web development, also a self taught developer.
            I have freelance experience creating multiple different projects (mostly front-end).
            I'm inspired of programming from the constant growth in technology.  I enjoy creating things as I have always had an artistic mind; so mixing the passion of creativity, with my love for tech programming feels perfect for me.`
  const nav = document.getElementsByTagName("nav")[0];
  const header = document.getElementsByTagName("header")[0];
  header.insertBefore(textArea, nav);
}
#itg {
    height:150px;
    width:150px;
    border-radius:50%;
    align:top;
}
body {
    background-image:url("codercup.png"),linear-gradient(to right,white,#c3c3c3);
    background-repeat: no-repeat;
    background-size: 600px, 700px;
    background-position:bottom,center;  
}
    
li {
    list-style-type:none;
    padding:0;
    margin:0;
    font-size:20px;
}
    
h1 {
    text-align:center;
}
    
nav {
    float:right;
    height:500px;
}

.resume {
    align:bottom-left;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Evin McReynolds Portfolio</title>
  
  </head>

<body>
    <header>
    <h1><strong>About Evin</strong></h1>
        <img src="ITguy.jpeg"class="itg" id="itg" onclick="myFunction()"/>  
        
        
                 
        <nav>
            <ul class="link">
                <li><a href="EMport.html">Home</li></br>
                <li>About Evin</li></br>
                <li><a href="contactem.html">Contact Evin</a></li></br>
                <li><a href="skillsem.html">Skills</a></li></br>
                <li><a href="EvinPro.html">Projects</a></li>
            </ul>
        </nav>
        
        </p>
        </header>
        <section>
        
        <embed src="evinITresume.pdf"width="350px" height="400px" class="resume"/>
        </section>
</body>

</html>

Answer №1

To locate the textarea by id, you must first search for it. If it is found, remove it and halt the function. If it is not found, proceed with generating the textarea.

function myFunction() {
  const exists = document.getElementById("text");
  if (exists) {
    exists.remove();
    return;
  }
  const textArea = document.createElement("textarea");
  textArea.rows = 10
  textArea.id = "text";
  textArea.cols = 30;
  textArea.readonly = true;
  textArea.innerHTML = `I have been learning and creating web page content since 2015.  
            I'm a part-time student in Information Technology with a concentration in web development, also a self taught developer.
            I have freelance experience creating multiple different projects (mostly front-end).
            I'm inspired of programming from the constant growth in technology.  I enjoy creating things as I have always had an artistic mind; so mixing the passion of creativity, with my love for tech programming feels perfect for me.`
  const nav = document.getElementsByTagName("nav")[0];
  const header = document.getElementsByTagName("header")[0];
  header.insertBefore(textArea, nav);
}
<style>#itg {
  height: 150px;
  width: 150px;
  border-radius: 50%;
  align: top;
}

body {
  background-image: url("codercup.png"), linear-gradient(to right, white, #c3c3c3);
  background-repeat: no-repeat;
  background-size: 600px, 700px;
  background-position: bottom, center;
}

li {
  list-style-type: none;
  padding: 0;
  margin: 0;
  font-size: 20px;
}

h1 {
  text-align: center;
}

nav {
  float: right;
  height: 500px;
}

.resume {
  align: bottom-left;
}

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

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Evin McReynolds Portfolio</title>

</head>

<body>
  <header>
    <h1><strong>About Evin</strong></h1>
    <img src="ITguy.jpeg" class="itg" id="itg" onclick="myFunction()" />



    <nav>
      <ul class="link">
        <li><a href="EMport.html">Home</li></br>
                <li>About Evin</li></br>
                <li><a href="contactem.html">Contact Evin</a></li>
        </br>
        <li><a href="skillsem.html">Skills</a></li>
        </br>
        <li><a href="EvinPro.html">Projects</a></li>
      </ul>
    </nav>

    </p>
  </header>
  <section>

    <embed src="evinITresume.pdf" width="350px" height="400px" class="resume" />
  </section>
</body>

</html>

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 ensuring the final row remains fixed at the bottom of the table while maintaining a minimal body height:

I'm currently working on designing an invoice table using HTML and CSS. I have dynamic rows that are added to the table, and I want the body of the table to have a minimum height to fit around 5-6 rows, after which it should extend based on the number ...

SequelizeDatabaseError: The operation could not be executed as there is no operator that allows for

I am attempting to create a join between two tables using UUIDs (also have IDs), and the relationships between these tables are quite complex... However, I encounter an error when running the query. The first table is named users, with its UUID labeled a ...

Choosing the Laravel 6 option for editing via AJAX: A step-by-step guide

I am looking to update a user who resides in a specific state within a country. The country and state fields are dropdown select options, with a relationship established between them and the user. The state field is populated based on the selected country. ...

How to dismiss a jQueryMobile dialog without triggering a page refresh

I've encountered a question similar to this before, but there wasn't any solution provided. The issue I'm facing is that I have a form and when a user clicks on a checkbox, I want to open a popup/dialog for them to enter some data. However, ...

What purpose is served by the use of '.src' in Next.js?

When working with Next.js, I encountered a situation where I needed to set a background image. After doing some research, I came across a solution that involved adding .src at the end of the image reference like this: import bgImg from '../public/imag ...

Combining various JSON objects by nesting them together

I'm in the process of creating an endpoint where I need to combine data from four different tables into one nested object. Each table record is retrieved in JSON format using sequelize - they include information on location, service, staff, and tenant ...

Troubleshooting Unresolved Issues with MongoDB and Node.js Promises

In my node.js code, I have utilized MongoDB to retrieve certain numbers. Below is the snippet of my code: MongoClient.connect('mongodb://localhost:27017/mongomart', function(err, db) { assert.equal(null, err); var numItems = db.col ...

What is the process for changing the background color when a button or div is pressed, and reverting the color back when another button or div is

Looking to customize a list of buttons or divs in your project? Check out this sample layout: <button type="button" class="btn" id="btn1">Details1</button> <button type="button" class="btn" id="btn2">Details2</button> <button ty ...

The correct way to write media queries in CSS for the iPhone

After successfully formatting a website for various devices using an online responsive design tester and CSS declarations like @media only screen and (max-width: 480px), I encountered an issue during testing on an actual iPhone. The browser was not computi ...

`Is there a way to manage date formats across all components using a single method in Angular?`

I need assistance with controlling the date format of dates displayed in different components using one typescript file. How can I achieve this? app.ts import { Component } from '@angular/core'; @Component({ selector: 'app-root', ...

Encourage users to activate the physical web feature in compatible web browsers

Is it possible to use JavaScript to encourage users to activate the physical web (and thus BlueTooth), similar to how APIs like "getUserMedia()" prompt users? UPDATE: Given that this technology is still in its early stages and not extensively supported, t ...

Display or conceal a div element using a dropdown menu selection

I have implemented the following code, which is currently functional and was sourced from a different thread on Stack Overflow: <Select id="colorselector"> <option value="red">Red</option> <option value="yellow">Y ...

Compile the sources of an npm dependency using Brunch

Recently, I've been facing an issue while trying to develop my web application using Brunch. The problem arises from a specific npm package called animated-vue, which consists of sources programmed in ES2016. After adding this package as a dependency ...

The background-size property in CSS does not seem to properly display on iPhones

Hello there! I'm facing an issue with my CSS code when it comes to displaying the image on Safari browser. It works perfectly fine on other browsers, but for some reason on Safari, the image doesn't show up correctly. I tried using a media query ...

Definition of TypeScript type representing the value of a key within an object

As I delve into defining custom typings for a navigation library using TypeScript, one challenge that has me stumped is creating a navigate function. This function needs to take the Screen's name as the first argument and the Screen's properties ...

Creating a disabled HTML button that reacts to the :active CSS pseudo class

CSS: button:active { /* active css */ } button:disabled { opacity: 0.5; } HTML: <button disabled="disabled">Ok</button> After clicking the button, the browser applies the button:active state to give the appearance of a click, despite the ...

Executing `console.log()` in Windows 8 using JavaScript/Visual Studio 2012

Whenever I utilize console.log("Outputting some text") in JavaScript within Visual Studio 2012 for Windows 8 metro development, where exactly is the text being directed to? Which location should I look at to see it displayed? Despite having the "Output" pa ...

The element does not recognize the property 'width' since it is not defined in the type of 'GlobalEventHandlers'

I'm trying to determine the size of an image using JavaScript, but I encountered a TypeScript error: const img = new Image(); img.onload = function() { alert(this.width + 'x' + this.height); } img.src = 'http://www.google.com/intl/en_ ...

Discovering Angular 2 Service Change Detection

Exploring the Angular 2 beta has led me to some challenges with understanding the change detection mechanism. I have put together a simple Plunker example that demonstrates an issue I am encountering. //our root app component import {Component, Injectab ...

Error: Attempting to access an undefined property

I have a quite extensive Vue/Vuitify project that is not functioning correctly. I have simplified the project down to a small program to highlight the issue. Despite trying everything that comes to mind, and even some things that don't, I am unable to ...