Use CSS to mimic the :hover functionality for touchscreen devices

I am struggling to get this piece of code to function correctly,

$(document).ready(function() {
    $('.hover').bind('touchstart touchend', function(e) {
    e.preventDefault();
    $(this).toggleClass('hover_effect');
});

Could you please take a look at my JSFiddle test script?

Appreciate your assistance!

Answer №1

You have attached the 'touchstart touchend' event to the '.hover' class, but there are no elements with this class. Instead, try attaching it to the 'p' element like this:

$(document).ready(function() {
    $('p').bind('touchstart touchend', function(e) {
        e.preventDefault();
        $(this).toggleClass('hover_effect');
    });
});

You may also use a more specific selector than just 'p'.

Additionally, make sure to load the jQuery library in your jsfiddle.

http://jsfiddle.net/8PxXL/

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 eliminating a worldwide ajax event handler using jQuery

Although it may not be the most advanced question (I am a beginner in JQuery), I am facing an issue: Whenever a specific button is clicked on my website, I must add a function that registers a global ajax event handler (.ajaxSend to be precise) and verifi ...

What are the steps for implementing the innerClass style on the searchBox within the appBase?

I'm currently incorporating the searchBox component from appbase io into my upcoming js web application, but I've been facing challenges in customizing the layout of both the search box and the list. Despite following the documentation which sug ...

What is the reason behind opting for ng-style over style in AngularJS for applying CSS formatting?

Recently, I've delved into AngularJS and have been exploring its depths for a few days now. I'm curious about the use of ng-style in styling components within both static and dynamic webpages. Given that we already have the traditional style tag ...

Select the radio button by hovering the mouse over it

Is there a way to check my radio buttons when hovering over them without having to click? I want to display photos based on the selected radio button. I attempted this using JQuery, but I am still learning and consider myself a beginner. ...

Is there a way to automatically dismiss a notify.js notification?

I am currently attempting to forcefully close an opened notification by clicking a button, following the instructions provided in the advanced example of the notify.js API. Can someone please explain how this can be accomplished? function CLOSE() { $( ...

Tips for arranging a column using a personalized display function in Handsontable

Handsontable version 0.34.2 (current version, unable to upgrade) I have a homepage displaying customer details using Handsontable. The first column is the ID column, which is a clickable HTML link. When clicked, it shows the customer's detailed infor ...

Receiving an HTTP 405 Error? The Post method may function on one page but encounter issues on another (specifically with AJAX, Jquery, $.post

I'm facing a perplexing issue that has me puzzled. My website is currently hosted on IIS (in the testing phase, so everything is running through localhost). Using IIS 7.5 In my homepage (written in HTML), I have successfully implemented a PHP scrip ...

"Exploring the magic of Vue.js and Three.js: A guide to seamlessly changing CSS style elements within an

I'm currently in the process of converting my Three.js project to Vue.js Within my Three.js scene, I have a 3D model with HTML points of interest attached to it. It is crucial that these points remain fixed to the model and consistently face the cam ...

When making a request for "/example.php/" the CSS does not seem to take effect, however, the content is displayed properly

Currently, I am working on a PHP script where I have divided each section into separate .php files and included them using the include() function. Here is an example of how everything is set up in different folders: header.php footer.php etc.. When acc ...

Discover the art of effortlessly depositing elements into a spontaneously generated DIV, while luxuriating in the

Below is the jQuery code I am currently utilizing: jQuery(function() { jQuery(".component").draggable({ // utilize a helper-clone that will be appended to 'body' and not confined by a pane helper: function() { return jQuery(this ...

Determining the aspect ratio of an image is essential in using flexbox to achieve consistent heights

Recently, I came across a fascinating code pen titled: this demonstration of equal responsive height images I am determined to make sure that all images have the same height, regardless of their width/height variances. The CSS displayed below utilizes fle ...

The input value is displaying one value, but the output is showing a different value

I am encountering a unique issue and could really use some assistance. <input class="testVal" type="number" id="GT_FIRING_TEMPERATURE" value="-17" name="degC" onchange="angular.element(this).scope().unitConversion(value,name, id)"> Despite the valu ...

The art of layering images: How to stack one image on top of another

I am in the process of trying to place a logo on top of an image, but I have been unsuccessful so far. Rather than overlapping, the second image is appearing next to the first one. Can you help me figure out how to solve this issue? This is for a website ...

The Google map is not appearing when placed within the "row" class

My goal is to showcase Google Maps on my website, and every time I try to do so using the following code: <div class="large-12 columns" id="map-canvas"></div> The map displays perfectly and works as expected. However, when I nest this div wi ...

`<a> The value does not appear upon page load`

As a newcomer to development, I am currently experimenting and creating a sample dashboard. However, I am facing an issue where the sidebar value does not display upon loading the page. I have to manually click on a list in my sidebar for it to appear. Th ...

The specified CSS background image is not correctly aligned with the dimensions of the selector

I have multiple non-local images that I want to use as background images for classes with a width of 500px and height of 330px. Even though these dimensions are specified in the CSS properties for the class, the background: url('http://www.example.com ...

unable to connect with the server

I'm facing an issue with an ajax call. It seems to work perfectly when testing in the browser, but when using ajax, it doesn't get called. The URL causing trouble is: Upon checking in Firefox's inspect element console, after sending the req ...

Is there a way to move the submit form button to the next line using CSS?

I am having trouble centering the submit button below two input fields in a simple React form. Can anyone offer assistance with this? HTML .SearchBar-fields { display: flex; justify-content: center; margin-bottom: 2.88rem; flex-direction: row; ...

What is the correct way to utilize Html.Raw(Json.Encode(Model))?

I'm facing an issue with encoding my MVC Model using the code snippet below. The alert message is returning a null value, which is confusing to me since this is a create form. The HTML code structure is as follows: @using (Html.BeginForm()) { @H ...

An effective way to prevent right-clicking on iframes across all websites

I am facing an issue with disabling right click for the iframe. I've successfully disabled it for the default URL of the IFrame, but when displaying any other webpage, the right click remains usable. Below are the sample codes I have used: document.o ...