Transforming the appearance of web elements using jQuery (graphic)

While there are numerous resources on changing CSS with jQuery, I seem to be having trouble getting my image to hide initially and show up when a menu tab is clicked. Any help would be greatly appreciated! ;)

h1 {
  text-align: center;
}

.Menu {
  width: 550px;
  height: 18px;
  text-align: center;
  margin: 0 auto;
  
}

li {
  width: 100px;
  float: left;
  padding: 10px;
  display: block;
  background-color: green;
  margin: 0 auto;
  text-align: center;
  height: 18px;
}

ul {
  list-style-type: none;
  margin: 0 auto;
}

li:hover {
  color: cyan;
  background-color: pink;
  cursor: pointer;
}
body {
  background-color: cyan;
}

.image {
  text-align: center;
}

img {
  border: 4px solid black;
  border-radius: 25px;
visibility: hidden;
}
<h1> 29/12/'2016 </h1>
<div class="Menu">
  <ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  </ul>
</div>
<br></br>
<div class="image">
<img src="https://www.google.be/images/branding/googleg/1x/googleg_standard_color_128dp.png" width= 200px alt="Smiley face"/>
</div>
<script>
$("document").ready(function(){
  
   $("li").on("click",function(){
  $('img[Smiley Face]').css("visibility","visible");   
});
    
  });

</script>

Answer №1

Your original jQuery selector was incorrect. Here is the correct way to specify the attribute you want to select, paying attention to case:

$('img[alt="Smiley face"]')

While this method works, it's not the most common way to select an element. It would be better to give the <img> an ID or class for easier targeting. Example:

HTML: <img id="smiley" src="image.jpg" />

jQuery: $('#smiley')

Here is your updated snippet with the issue fixed:

$("document").ready(function() {

  $("li").on("click", function() {
    $('img[alt="Smiley face"]').css("visibility", "visible");
  });

});
h1 {
  text-align: center;
}
.Menu {
  width: 550px;
  height: 18px;
  text-align: center;
  margin: 0 auto;
}
li {
  width: 100px;
  float: left;
  padding: 10px;
  display: block;
  background-color: green;
  margin: 0 auto;
  text-align: center;
  height: 18px;
}
ul {
  list-style-type: none;
  margin: 0 auto;
}
li:hover {
  color: cyan;
  background-color: pink;
  cursor: pointer;
}
body {
  background-color: cyan;
}
.image {
  text-align: center;
}
img {
  border: 4px solid black;
  border-radius: 25px;
  visibility: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>29/12/'2016</h1>
<div class="Menu">
  <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
  </ul>
</div>
<br><br>
<div class="image">
  <img src="https://www.google.be/images/branding/googleg/1x/googleg_standard_color_128dp.png" width=200px alt="Smiley face" />
</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

Choose just one column within an HTML table

Is there a way to easily select the text of a single column from an HTML table using just the mouse pointer? Imagine you have a table that looks something like this: https://i.sstatic.net/n3lZR.png When trying to select only the text in the Lastname col ...

Display a "Saving...." animation on the screen as a record is being saved to the database

There are a couple of ways to approach this design: One option is to use a gif file. When the Save button is clicked, a "Saving..." gif file will be displayed on screen for a hardcoded delay before the record is saved to the database. However, this may ...

Utilize LESS Bootstrap as a guide for incorporating content

I have been struggling to properly integrate Bootstrap into my LESS file. Currently, I am adding Bootstrap to my project using NPM. If I simply use the following import statement in my LESS file: @import (reference) 'node_modules/bootstrap/less/boot ...

Divide a SINGLE BACKGROUND IMAGE in HTML into two separate links of equal size, one at the top and

As a beginner in HTML, I am trying to find a way to divide a background image into two equal sections without using image mapping. I attempted to split the links by setting the style to 0% and 50% to designate the top and bottom halves, but unfortunately, ...

Changing the data type of an integer to a string within an Object

I'm working with two arrays of objects. I need to convert the data values in the first format from integers to strings, but I'm struggling to find a simple solution. Is there anyone who can provide assistance? https://i.sstatic.net/mzqWE.png If ...

What is causing the unusual behavior of z-index in this specific scenario?

I have a good understanding of z-index and decided to practice with it by writing the following code: *{ padding: 0; margin: 0; box-sizing: border-box; } body{ height: 100vh; di ...

What is the best way to adjust the mobile screen size to display the most optimized version of a web app's

Currently, I am utilizing react, Bootstrap, and some custom sass to construct and style the front end of my web application. While the design appears good on mobile devices, there is an issue where users need to pinch the screen due to it looking slightly ...

Best docker image containing both Node.js and Deno for optimal performance

Is there an efficient Docker configuration to run both Node and Deno that you recommend? I have tried the following setup, but I am open to suggestions for optimization. Any insights or advice would be highly appreciated. Thanks! FROM mcr.microsoft.com/v ...

What could be causing the sporadic functionality of my jQuery image resizing code?

Seeking help for an issue I am facing with my jQuery code. I have been trying to scale a group of images proportionally within an image carousel using jCarousel Lite plugin. However, the resizing code seems to work randomly and I can't figure out why. ...

Creating a Delicious Earth Progress Pie

I'm looking to incorporate a unique progress bar design on my website, similar to this one: The progress pie Can anyone guide me on how to create a progress pie with an image inside it that changes color as it moves? ...

Cypress: harnessing the power of regular expressions within jQuery selectors for the ":contains()" method

Trying to use Cypress along with a regular expression to target an element that includes specific text. The following get() function successfully works: cy.get('[data-cy=tile]').contains(new RegExp(myVar)) However, the following command does no ...

Form submission fails to trigger AJAX execution

When a form is submitted, I have the jQuery ajax code below that should be executed: <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <script> $("form").submit(function() { $.ajax("/myapp/rest/customer/created ...

What is the best way to incorporate bullet points into a textarea?

How can I make a bullet point appear when pressing the 'enter' button inside a textarea? I tried using this code, but it doesn't seem to work. Any suggestions? <script> $(".todolist").focus(function() { if(document.getElementById( ...

Leveraging SignalR in conjunction with jQuery to dynamically alter the CSS style of a span

Utilizing SignalR to dynamically update a span's color based on real-time data source. The connection is established successfully, but encountering difficulties with updating the css classes on the span. The issue arises when attempting to update mul ...

I'm having trouble adjusting the link color in my footer text while navigating Wordpress for the first time

As someone who is new to Wordpress, I am struggling with changing the link color in the footer text. Despite spending hours on it, I just can't seem to figure it out. The files I have been working with are style.css and bootstrap.min.css. I feel lik ...

A collapsible select list with checkboxes for children items

I am currently developing a website using Vue.js, HTML, and SCSS. I am looking to implement a drop-down functionality similar to the animated example provided in the gif below: https://i.stack.imgur.com/Mia2D.gif The gif demonstrates how the drop-down me ...

A step-by-step guide on integrating HTML form input with an API object array

I'm looking to combine two code "snippets" but I'm not sure how to do it. One part of the code turns HTML form input into a JSON object. You can see the CodePen example here. What I want is when the "Add note" button is clicked, I want to grab ...

Styling is lost in FancyBox popup when loading Partial View

I've been attempting to incorporate a partial view into my MVC project using fancybox. It seems to be loading the content correctly, mostly anyway, as it tends to cut off part of the page and loses all styling from the view upon loading. Even after i ...

Date Selector Tool for Input Field

Does anyone know how to change the color of the date picker that appears in certain browsers but is unsure about the selector's name? HTML: <form action="pledge.html" method="post"> <input type="date" id="birthday" name="user_bda ...

Dealing with JSON feed and function events problem with jQuery fullcalendar in Internet Explorer

Currently, I am utilizing jQuery fullcalendar in conjunction with Grails. Initially, I was utilizing events (in the form of a json feed) and observed that each time the user clicks on prev/next or changes views, the json feed URL is invoked. Considering t ...