Are JQuery event names a secure choice for class names within your code base?

While testing a remote site, I encountered an issue where the click event for an element is not functioning properly in certain Windows environments running Internet Explorer and Safari.

I've observed that elements with a clickable function have a class name of "click". The event is currently defined as follows:

$('.click').click(function() {

Before exploring other potential causes, could you confirm if this setup appears to be correct?

Thank you, Sean

Answer №1

Definitely, the correlation between jQuery/Javascript event names and CSS class names is completely up to the developer's discretion. It is important to note that these two aspects are not inherently connected until a developer intentionally links them together (or if using a framework where classes are typically prefixed).

Considering this, it might be beneficial to steer clear of using generic 'event-centric' class names in CSS. CSS, after all, focuses on styling elements rather than events. If you need to identify clickable elements, a better approach could be to assign them a custom attribute like data-clickable='true' and adjust your selector to target those specific elements with $('[data-clickable=true]'). This way, you uphold the separation between style (CSS), content (HTML), and function (JS) which is widely considered as best practice. However, returning to your original question, the manner in which you inquire about this relationship may not have a significant impact.

Answer №2

Without a doubt, it appears secure and actually is secure. There is no risk in utilizing event names as class names, as long as you remain clear-headed ;)

These are distinct entities. CSS and JS cannot clash with one another. Consequently, employing what you currently have is considered safe.

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

Pure CSS navigation - radio buttons to display or hide different pages

I'm attempting to create a website navigation bar using radio buttons, where the pages are displayed based on the selection. So far, I've managed to achieve this using <a href='#div'></a> and a :target, by placing the .page ...

Creating numerous duplicates of a highly nested immutable Object can be done by using a combination of spread operators

I am currently working on retrieving data from firebase/firestore using Javascript. I have created a function where I retrieve my products collection and pass this data to the React state.products by utilizing the setState() method. My objective is to tra ...

Creating a CSS animation to repeat at regular intervals of time

Currently, I am animating an SVG element like this: .r1 { transform-box: fill-box; transform-origin: 50% 50%; animation-name: simpleRotation,xRotation; animation-delay: 0s, 2s; animation-duration: 2s; animation-iterat ...

Troubleshooting: Angular Custom Elements malfunction on Firefox, Microsoft Edge, and Internet Explorer

Experimented with the Angular Elements Demo After downloading, installing, and building the demo locally. Implemented the following code: <!doctype html> <html lang="en> <head> <meta charset="utf-8> <title>Angular Eleme ...

The HTML code does not seem to be acknowledging the CakePHP link

When using Cakephp to generate a link with Html->link, the code looks like this: echo $this->Html->link('Download',array( 'plugin'=> 'galleries', 'controller'=> 'galleries', 'a ...

Personalizing Google Map pin

I found some code on Codepen to add pointers to a Google map. Currently, it's using default markers but I want to change them to my own. However, I'm not sure where in the code to make this update. Any examples or guidance would be appreciated. ...

I'm having trouble with the $locationProvider not functioning properly on my Angular webpage

I am facing an issue in my angular page where I am using a $locationProvider. However, it seems to not be functioning correctly on my web page. The console is showing an error message that says "$location in HTML5 mode requires a <base> tag to be pre ...

Creating a unique custom authentication controller in Strapi.OR

While using Strapi for my API and Back office, I've encountered a problem. Everything works fine except for one issue: I am struggling to override the controller used for the forgot password feature. Despite attempting to follow the documentation, par ...

Is there a common issue in web browsers? Neglecting the position relative attribute on 'tbody', 'tr', and 'td' elements?

Trying to absolutely position elements within tbody, tr, and td may not work in certain browsers. While it behaves as expected in Firefox, it does not work properly in IE, Edge, and Chrome. If you apply position: relative to tbody, tr, or td, it will be i ...

Creating a flipbook out of a PDF file

I am looking for a cost-effective solution to convert my numerous PDF files into flipbooks for easy reading. I have been unable to find a free tool for this purpose, so I am curious if it is possible to create a flipbook using only HTML, CSS, and JavaScr ...

Retrieving External JSON Data from a Server with Firefox

I've been developing a static local HTML5 charting application that retrieves data from a remote server for output. The code works perfectly in Google Chrome, as shown below, but I'm encountering difficulties getting it to function in Firefox. & ...

Combining TypeScript and JavaScript for efficient mixins

I came across an article on MDN discussing the usage and creation of mix-ins (link). Intrigued, I decided to try implementing it in TypeScript: type Constructor = new (...args: any) => any; function nameMixin(Base: Constructor) { return class extends ...

I'm having difficulty implementing a vue-awesome icon on my project

I am attempting to utilize the standard window-close icon from vue-awesome. I have imported my vue-awesome using the following code: import 'vue-awesome/icons'; import Icon from 'vue-awesome/components/Icon.vue'; Vue.component('i ...

Send data from input to controller without using $scope

I am encountering an issue with the code below. Typically, I would resolve this problem using $scope, but this time I have been asked to find a solution without utilizing $scope in the controller. I am implementing the "controller as" syntax for managing ...

Pause display as the window refreshes

Is there a way to freeze the screen while initiating a window reload so that it becomes unclickable during that time? var nTime = 1 * 50; window.setTimeout("location.reload()", nTime); I am currently using this method to reload my screen, but I am lookin ...

How to use Javascript to fetch HTML content from an external website

Is it possible to access and retrieve scores from for a specific week using AJAX or JSON technology? Each game on the website seems to have a unique class which could make retrieving score information easier. Any guidance or assistance would be greatly ap ...

Issues have been raised with IE11's refusal to accept string(variable) as a parameter for the localStorage

Why is it that Internet Explorer does not recognize a string variable as a parameter for the setItem method, even though it works fine in Chrome? For example, in IE: This code snippet works: var itemName = 'anyname'; localStorage.setItem(itemN ...

Display dynamic text from an input field in another div along with a checkbox

In the input field below, you can type something and then click the Add button. What will happen is that the text entered in the input field will be appended with a checkbox inside a div with the class .new-option-content. For a live example, check out th ...

Utilizing JSX interpolation for translation in React JS with i18next

I am trying to utilize a JSX object within the interpolation object of the i18next translate method. Here is an example code snippet along with its result: import React from "react"; import {useTranslation} from "react-i18next&qu ...

Attempting to design the appearance of the form fields within a Mat-Card

As someone new to UI development and lacking in-depth knowledge of css, I have been searching for examples to style a login page using Angular Material. My main struggle right now is getting the form fields to expand the width of the card (minus the paddin ...