The issue of Jquery .click event handler failing to work for class selector specifically in CHROME

Is there a way to achieve the same opacity effect on click as on mouseover? I've tried various selectors without success.

Any help on this issue would be greatly appreciated. Thank you in advance!

.container {
position: absolute;
background:url('../images/bgpic.png');
    background-repeat: no-repeat;
    background-size: cover;
margin: 0px;
padding: 0px;
height: 100%;
width: 100%;
}

.wrapper {
position: relative;
margin: auto;
padding: auto;
height: 655px;
width: 900px;
}

.titlehdr {
margin: 0px;
padding: 0px;
display: inline-block;
width: 897px;
height: 110px;
}

.title-div {
display: inline-block;
position: relative;
height: 100%;
width: 90px;

margin: 0px;
padding: 0px;
}


.title {
position: relative;
top: 40px;
margin: 0px;
padding: 0px;

font-size: 70px;
color: white;
font-family: Mesquite Std;
letter-spacing: 1.2px;

}

.barandgrill-div {
display: inline-block;
vertical-align: bottom;

}

.barandgrill-text {
margin: 0px;
padding: 0px;
font-family: Arial;
font-weight: bold;

}

/*---------------Nav Menu----------------*/
.menu {
padding-left: 0px;
margin-left: 0px;
font-size: 15px;
}

.nav-container {
text-align: center;
display: block;
top: 100px;
margin: 0px;
padding: 0px;
width: 900px;
height: 40px;
background-color: #901423;
border-style: solid;
border-width: 1px;
border-color: #111111;
}

.menu {
display: inline-block;
text-align: center;
margin: auto;
padding: auto;
 list-style-type: none;
  overflow: hidden;
    font-color: #000000;
}

.li-navclass {
  border-bottom: 1px solid #000;
}


li {
display: inline-block;
position: relative;
padding: 0 1em;
font-size: 150%;
}


.nav-text {
   color: #ffffff;
  font-weight: bold;
  opacity: .3;
}


.nav-container ul a {
text-decoration: none;
    word-spacing: 200px;
    margin: 0px;
    padding: 0px;
  font-size: 20px;
  font-family: Segoe Script;
}

/*---------------Content----------------*/

.content {
display: block;
width: 900px;
height: 500px;
border-style: solid;
border-width: 1px;
background-color: #111111;
opacity: 0.6;
}

/*---------------Footer------------------*/

.foot {
text-decoration: none;
list-style-type: none;
display: block;
position: relative;
text-align: center;
font-size: 12px;
}

.ftr-button {
position: relative;
top: -5px;
list-style: none;
text-decoration: none;
color: rgb(147, 104, 55);
}


.ftr-links {
text-decoration: none;
list-style-type: none;
}


.vert-line {
height: 13px;
border-right: 1px solid #909090;
}
<!DOCTYPE html>
<html lang="en">

<head>
<title>Sticky Navigation Tutorial</title>                  
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<link rel="stylesheet" media="screen, projection" href="css/screen.css"/>

</head>

<body>
<div class="container">

<div class="wrapper">


<!--Title-->
<div class="titlehdr">
<div class="title-div">
<p class="title">Donatelo's</p>
</div>

<div class="barandgrill-div">
<p class="barandgrill-text">Mediterranean Bar and Grill</p>
</div>
</div>

<!--Navigation Menu-->
<div class="nav-container">
<ul class="menu">
<li class="li-navclass"><a href="index.html" class="nav-text">Story</a></li>
<li class="li-navclass"><a href="menu.html" class="nav-text">Menu</a></li>
<li class="li-navclass"><a href="gallery.html" class="nav-text">Gallery</a></li>
<li class="li-navclass"><a href="catering.html" class="nav-text">Catering</a></li>
<li class="li-navclass"><a href="contact.html" class="nav-text">Contact</a></li>
</ul>
</div>

<!--Grey Box-->
<div class="content">
<div id="sidebar">
<div id="scroller">
</div>
</div>
</div>

<!--footer-->
<div class="foot">
<ul class="ftr-links">
<li class="vert-line"><a href="index.html" class="ftr-button">Story</a></li>
<li class="vert-line"><a href="menu.html" class="ftr-button">Menu</a></li>
<li class="vert-line"><a href="gallery.html" class="ftr-button">Gallery</a></li>
<li class="vert-line"><a href="catering.html" class="ftr-button">Catering</a></li>
<li class="vert-line"><a href="contact.html" class="ftr-button">Contact</a></li>
</ul>
<p class="copyright">Copyright © 2015 Agabi Mediterranean Restaurant</p>
</div>
</div>


</body>

<script>
$(document).ready(function(){
$(".nav-text").mouseover(function() {
  $( this ).css( "opacity", ".8" );
});

$(".nav-text").mouseout(function() {
$(this).css( "opacity", ".2");
});

$(".ftr-button").mouseover(function() {
$(this).css("color", "rgb(132, 131, 129)");
});
$(".ftr-button").mouseout(function() {
$(this).css("color", "rgb(147, 104, 55)");
});

$(".nav-text").click(function() {
$(this).css("opacity", ".8");
});
});
</script>

</html>

Answer №1

The reason for the issue is that the .nav-text element is nested inside an anchor tag, causing a new page to open when clicked. To prevent this behavior and perform custom actions instead, you can use event.preventDefault() within your jQuery click function.

Here's how you can implement it, although please note that your link will no longer navigate to a new page:


$(".nav-text").click(function(event) {
    event.preventDefault();
    $(this).css("opacity", ".8");
});

If this solution does not meet your requirements, consider exploring the :focus selector in CSS for alternative approaches: http://www.w3schools.com/cssref/sel_focus.asp

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

Can I modify individual properties of xAxis.labels in HighCharts?

I am seeking to customize the properties of my labels on the x-axis in a unique way (View my query here). I have a clear understanding of how to achieve this for dataLabels: See API reference. This process is akin to what has been explained here. Howeve ...

Combining a local URL with an absolute URL through jQuery AJAX

Currently, we are utilizing jQuery Ajax for a service get call: $.ajax({ url: _sbUrl + "gates/1.0/sweeps/getVehicleDetails/" + request.data.regn_no, method: "GET", success: function(response) { if (200 === response.statusCode) { if (typeof ...

jQuery: Locate and eliminate any images in the text that appear after a specific group of tags if no images are present

Currently, I am in the process of developing a feed reader specifically designed to parse the Google News Feed. You can view and test the code on this Fiddle. My main challenge lies in removing titles and sources from the descriptions. Through my explorati ...

There seems to be some odd behavior with the setIcon function in the Google Maps API

Initially, the marker.setIcon method didn't work for me. Upon inspecting the browser console, I encountered this message: https://i.sstatic.net/fpf6n.png To troubleshoot, I attempted using markerObject.icon = "/Content/img/icon_critical.svg", althou ...

A guide to replicating HTML using AngularJS

I am attempting to replicate HTML content using AngularJS. While I was successful using jQuery, it caused conflicts with Angular. Therefore, I aim to achieve the same result using AngularJS. Here is the code I have written: function printContent(el){ ...

The process of verifying the new password and confirming it using the [Compare("",..)] function seems to be malfunctioning when utilizing data annotations in MVC3 with Razor

I have three PasswordFor fields: oldpassword, newpassword, and confirmnewpassword inside my form using Ajax.BeginForm(). I need these values to be bound with a model and the values of newpassword and confirmnewpassword to be validated on the client side us ...

Tips for choosing a nested element within a div using CSS

I'm looking to target a specific child element within a div using CSS. Here's the HTML code I have: <div class='body'> <text>This is a text element</text> </div> Instead of adding a class or an ID, I want to ...

CSS rule for targeting an element that does not have any child elements

I have a variety of different elements that are structured similarly to the following.. <div id="hi"> <div class="head"> </div> <div class="footer"> </div> </div> ..however, some of these elements do no ...

Using for loop in AJAX Done() function

I'm currently working on a for loop that loops through an array consisting of 3 different report numbers. For each value in the array, an AJAX request is sent out. What I want to achieve is having a unique behavior for the .done() function based on th ...

Moving divs to a separate line in mobile display

I currently have a basic image-thumbnails landing page set up like this: <div style="display: inline-block;"><img style="margin: 3px 3px;" src="..." alt="" width="200" height="200" /></div> <div style="display: inline-block;"><i ...

Is there a versatile spell-checking tool available for HTML text boxes?

When designing a text box in HTML, I want to provide real-time input validation and spell check for the user's text. My goal is to underline any spelling mistakes as they type. This seems like a basic feature, but I've yet to find a plugin or AP ...

Tips on keeping a Material UI menu item open when clicked

My menu consists of a single item, which is a text field along with a button. The idea is to input some information, save it by clicking the button, and then close the menu either by hitting "close" or the original button again. How can I stop the MenuItem ...

What could be causing the jQueryUI dialog to malfunction in IE9?

The code provided above successfully creates a jQueryUI modal popup dialog in various browsers such as Firefox, Chrome, and Opera. However, it encounters issues when running on Internet Explorer 9: <html><head> <link rel="stylesheet" href= ...

Implement a jQuery slider that pauses on hovering

Currently, I am grappling with the clearInterval function in a small jQuery project. To better illustrate the issue, I have created a jsFiddle example: http://jsfiddle.net/eWTSu/ While the rotation works smoothly, I encountered an obstacle when hovering ...

Is it possible to create a fading effect on an image using a border-radius of 50%?

Struggling with fading out an image that's circular in shape due to the border-radius: 50%. <section id="main"> <h1>Non-Important-Text</h1> <h4> it's all fun and games until you can't find a damn sol ...

Preserve unencoded HTML content as a string

Here is an example string: text = '&lt;div class="blue"&gt; &lt;p&gt;This is a sample text string' When I use <%= text.html_safe %> in my webpage, it displays correctly, but not when I try it in the console. If I attempt: ...

Error: Unable to assign value to property 'src' because it is null

Currently, I am attempting to display a .docx file preview using react-file-viewer <FileViewer fileType={'docx'} filePath={this.state.file} //the path of the url data is stored in this.state.file id="output-frame-id" ...

Trigger price update in jquery based on radio or checkbox selection and specific conditions

https://i.sstatic.net/OIvgF.png In my product form, I have implemented a feature where selecting the "product type" and "product size" will update the price. However, if the user changes the product type after selecting the size, the price does not update ...

``I am experiencing issues with the Ajax Loader Gif not functioning properly in both IE

I am brand new to using ajax and attempting to display a loading gif while my page loads. Interestingly, it works perfectly in Firefox, but I cannot get it to show up in Chrome or IE. I have a feeling that I am missing something simple. The code I am using ...

Is there a way to determine the actual time or percentage completion of a file upload using Telerik RadUpload?

Utilizing the Telerik upload file control with manager is a key component of my project: <telerik:RadUpload ID="RadUpload" Runat="server" MaxFileInputsCount="5" /> <telerik:RadProgressManager ID="RadProgressManager" Runat="server" /> For clie ...