The website is failing to extend and reveal content that is being concealed by jQuery

I'm currently diving into the world of Javascript and jQuery, attempting to create a functionality where upon clicking the submit button, the website dynamically expands to display search information. Although the feature is still in progress, I am utilizing a test div to visualize its placement, which unfortunately isn't fully visible. Moreover, there seems to be no expansion happening on the site nor any scroll features appearing.

Here's the HTML snippet:

<!DOCTYPE html>
<html lang="end">
<head>
    <meta charset="utf-8" />
    <title>League of Legends Summoner Stats</title>
    <link rel="stylesheet" href="main.css" />
    <link rel="stylesheet" href="main.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>
<div class="center">
    <select class="region_selector">
        <option value="NA">North America</option>
        <option value="EUW">EU West</option>
        <option value="EUNE">EU East</option>
        <option value="KR">Korea</option>
    </select>
</div>
<div id="title">
    <h1>LoL Stat Find</h1>
</div>
<div id="subtitle">
    <h3>Quickly Find Summoner Stats!</h3>
</div>
<button type="submit" id="search_button">Search</button>
<input name="summoner_name" type="text" maxlength="512" id="summoner_name" placeholder="Summoner Name" class="summoner" />
<script src="script.js"></script>
<div id="stats">
    <section id="main">
        <h1>THIS IS A TEST</h1>
        some more testing
        <br>this is another test
        <br>another
    </section>
</div>
</body>
</html>

This is the CSS code:

body {
    background-image: url("background.jpg");
    width: 100%;
    background-size: 100%;
}
.region_selector {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 150px;
    /* bring your own prefixes */
    transform: translate(-100%, -50%);
    display: inline;
}
#summoner_name {
    position: fixed;
    top: 50%;
    left: 50%;
    /* bring your own prefixes */
    transform: translate(5%, -50%);
    display: inline;
}
.summoner {
    font-size: 14px;
    border-width: 2px;
    border-radius: 5px;
}
#search_button {
    position: fixed;
    top: 50%;
    left: 50%;
    /* bring your own prefixes */
    transform: translate(-50%, 100%);
    display: inline-block;
    margin: 0 10px 0 0;
    padding: 5px 15px;
    font-size: 15px;
    color: white;
    background-color: #1947D1;
    font-family: Tahoma;
    line-height: 1.8;
    appearance: none;
    box-shadow: none;
    border-radius: 5px;
    border-color: #1947D1;
}
#title {
    position: fixed;
    top: 50%;
    left: 50%;
    /* bring your own prefixes */
    transform: translate(-50%, -110%);
    display:inline;
    color: white;
    font-size: 48px;
    -webkit-text-stroke-width: 1px;
    -webkit-text-stroke-color: black;
}
#subtitle {
    position: fixed;
    top: 50%;
    left: 50%;
    font-size: 20px;
    /* bring your own prefixes */
    transform: translate(-50%, -130%);
    font-family: tahoma;
    -webkit-text-stroke-width: 1px;
    -webkit-text-stroke-color: black;
    display: inline;
    color: #009933;
    font-style: bold;
}
#stats {
    position: fixed;
    top: 50%;
    left: 50%;
    /* bring your own prefixes */
    transform: translate(-50%, 200%);
}

This is the related Javascript excerpt:

$(function () {
    $("#stats").hide();
});
document.getElementById('search_button').onclick = function () {
    var search = document.getElementById('summoner_name').value;
    $(function () {
        $("#stats").show();
    });
}

Being new to HTML/CSS/JS, my code may be all over the place at the moment.

Answer №1

When utilizing jQuery, make sure to use it for registering the click handlers and resolve the issue with the styles applied to #stats

$(function() {
  $("#stats").hide();

  $('#search_button').click(function() {
    $("#stats").show();
  });
});
body {
  background-image: url("background.jpg");
  width: 100%;
  background-size: 100%;
}
.region_selector {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 150px;
  /* include necessary prefixes */
  transform: translate(-100%, -50%);
  display: inline;
} 

//CSS code truncated for brevity

#stats {
  position: fixed;
  top: 1px;
  <!--here is the problem --> left: 50%;
  /* bring your own prefixes */
  transform: translate(-50%, 200%);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="center">
  <select class="region_selector">
    <option value="NA">North America</option>
    <option value="EUW">EU West</option>
    <option value="EUNE">EU East</option>
    <option value="KR">Korea</option>
  </select>
</div>
<div id="title">
  <h1>LoL Stat Find</h1>
</div>
<div id="subtitle">
  <h3>Quickly Find Summoner Stats!</h3>
</div>
<button type="submit" id="search_button">Search</button>
<input name="summoner_name" type="text" maxlength="512" id="summoner_name" placeholder="Summoner Name" class="summoner" />
<div id="stats">
  <section id="main">
    <h1>THIS IS A TEST</h1>
    some more testing
    <br/>this is another test
    <br/>another
  </section>
</div>

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

What is the best way to implement this design using CSS flexbox?

I'm working on designing a simple layout that looks like this: https://i.stack.imgur.com/oCzyV.png Currently, I have the following HTML structure with some variations in class names and additional markup within each element: <div class="site ...

Issue in TypeScript where object properties may still be considered undefined even after verifying using Object.values() for undefined values

I'm encountering an issue with TypeScript regarding my interface MentionItem. Both the id and value properties are supposed to be strings, but TypeScript is flagging them as possibly string | undefined. Interestingly, manually checking that id and va ...

Exploring a GitHub image repository with HTML loops

I need assistance with incorporating a gallery into my GitHub pages website. Within my username.github.io directory, I have an assets/images folder containing various images that I want to display by looping through them. After searching for a solution, I ...

Inserting HTML content into a DIV with the help of jQuery

Looking for a solution with my index.html file. I want to load other HTML files into a DIV by clicking on buttons. Here's an example of what I'm trying to achieve: I've searched through various examples online, but none seem to work for ...

The use of JQuery repeating fields can cause disruptions to the Bootstrap layout when removing rows

I have been struggling with a form that contains multiple fields that need to be repetitive. My current code is functional, but I'm encountering an issue where clicking on any remove button other than the first one causes the fields in the row to rear ...

Vue - Display components next to sidebar

Having an issue with the vue-sidebar-menu. The sidebar is appearing over the components instead of beside them. Here is a screenshot of the problem: <template> <div id="app"> <sidebar-menu :menu="menu" /> <vue-page-transit ...

Is the div empty? Maybe jQuery knows the answer

I currently have a <div id="slideshow"> element on my website. This div is fully populated in the index.php file, but empty in all other pages (since it's a Joomla module). When the div is full, everything works fine. However, when it's emp ...

Stop the span within the paragraph from breaking onto a new line

I have a situation where I need quote symbols to be placed inside span elements that are children of a p element. Each quote symbol requires slightly different CSS styles, and they must be included in the HTML rather than in the CSS due to backend restrict ...

HTML with embedded PHP script

i cannot seem to display mysql data in html format. the table i am working with is called App appid | app | version | date | apk file | 1 sample 1.0.0 2012-10-12 sample.apk //here is the mysql query ...

I encountered an error stating that ".then" is not defined during my attempt to save

Just starting out with node.js and I encountered an issue: TypeError: Cannot read property 'then' of undefined This is the code snippet causing the problem: router.post("/signup", (req, res) => { const userRegister = new UserRegister({ ...

What is the best way to eliminate the nesting in this ternary operation?

Object.values(filter).filter(item => (Array.isArray(item) && item.length > 0) || (typeof item === "boolean" && item === true) || (item !== null)).length ? filterIcon : unFilledIcon In this code, I aim to simplify the nested ternary operator and ...

Developing an ASP application using the MVP pattern to return JSON data can be transformed into a S

I’m looking to incorporate the following code into a sails js Controller public JsonResult GetEvents() { //Using MyDatabaseEntities as our entity datacontext (refer to Step 4) using (MyDatabaseEntities dc = new MyDatabaseEntities()) { ...

Creating Custom Filters in Angular using Functions

Attempting to filter ng-repeat using a function instead of an actual filter has presented some challenges. The code snippet below demonstrates the attempt: <tr ng-repeat="(key, value) in dataObj| filter:dataFilter"> The intention is to define dataF ...

Issues arise with AJAX authentication request

Currently, I'm working on incorporating a basic login form with an AJAX request that forwards the user to a page for querying my database. Depending on the results, the user is then redirected to the main index page or prompted back to the login form. ...

Resizing Div elements in React

I am currently working on a Drawer navigation feature and I am exploring the option of enabling mouse drag resize functionality. To achieve this, I have included a div element where I listen for the onMouseDown event. Once triggered, I then add an event li ...

I'm experiencing an issue where my express-session is being reset with every new request, leading me to question if this is related to the development environment I am using (REACT + EXPRESS)

UPDATE - I have ruled out a development environment issue as the same problem persists in production. Thank you for taking the time to look into this. I've searched through numerous questions and attempted various solutions with no success. To give ...

Identify a specific sequence within a text box, and alternate between two radio buttons

Within my search field, I have integrated two radio buttons that allow the user to choose between a regular keyword search or a license plate search. By default, the "keyword" option is pre-selected. However, I am looking for a way to use jQuery to automa ...

An error occurred when attempting to set state within a nested fetch

Having difficulty solving an issue with react.js. loadFromServer(pageSize) { fetch('http://localhost:8080/api/employees') .then(response => { return fetch('http://localhost:8080/api/profile/employees', ...

Alter the color of H3 when clicked and then gently fade it back

Is it possible to create a button on the top of my webpage that scrolls to a specific DIV when clicked, and also have it change the color of an h3 element once it has scrolled to it? This effect is similar to how Facebook highlights notifications. This is ...

Dealing with errors in a sequelize ORM query: Tips and tricks

Currently, I am implementing Sequelize ORM in my Node/Express project using Typescript. Within the database, there is a 'users' table with a unique column for 'email'. As part of my development process, I am creating a signIn API and ...