Apply a CSS class to specific text inputs with an "onclick" attribute

Need help with text inputs that have onclick functions.

Looking to assign a specific CSS class to text inputs with a certain onclick function.

Attempted to use this jQuery code:

$(document).ready(function(){
    $('input').each(function() {
       if($(this).attr("onclick") == "datetime_picker" && $(this).val() == "") {
            $(this).addClass("DateTimePickerInput");
       }
    });
});

Unfortunately, it did not work as expected.

Answer №1

Give this a shot:

$(document).ready(function(){
    $('input').each(function() {
        if ($._data(this, 'events')['click:datetime_picker']) {
            $(this).addClass('DateTimePickerInput');
        }
    });
});

Update:

Consider using this code instead:

$('input').each(function() {
    if ($(this).is('[onclick^=datetime_picker()]')) {
        $(this).addClass('DateTimePickerInput');
    }
});

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

The image link leading to the homepage lacks the functionality to be clicked on

My website has a logo on the top left that links to the home page, but only some areas of the image are clickable. It seems like the clickable and non-clickable areas are scattered randomly. How can I ensure that the link works across the entire area of ...

I'm looking to use JQuery's .load function to transfer content from one URL to another

I am looking to dynamically load content from a div with the ID maininner on a specific URL within my website into another div with the ID yurt1_avail on a different URL also on the same site. I have conducted a successful test outside of the CMS using ...

vertical alignment, almost there

Is there a way to align a block of text so that the top of the first line is positioned 50% down from the top of the td element? Imagine this scenario, where the top of the first row is exactly at the 50% mark. -------------- | | | ...

Stop a hyperlink from displaying with CSS

I have a widget that includes the following default line of code. <a href="javascript:map_Location.clearFeatures()">Delete all Features</a> However, I do not want this hyperlink to be visible. Initially, I attempted to apply the style - id_ ...

Arranging Functions in JavaScript

I am encountering an issue regarding the execution of JavaScript functions within HTML. Specifically, I am using dimple.js to create a graph and need to select an svg element once the graph is created via JavaScript. Despite placing my jQuery selector as t ...

Guide to displaying a table enclosed in a div based on a selected value in a select dropdown?

I am attempting to retrieve the table options using the select question-picker: Here is what I have tried: $(document).ready(function() { var question_container = $('.question-picker option[value="1"]').parent(); console.log(question_cont ...

A guide on using key arrows in JavaScript to navigate and focus on elements

When working on my HTML project, I have a list of elements that I want to be able to select using the arrow keys. I've included my code here for reference: [http://jsfiddle.net/T8S7c/] What I'm trying to achieve is when the arrow keys are press ...

Executing a Visual Basic subroutine from a jQuery dialog box

Currently, I have a form that includes a jQuery dialog creation. Within this dialog, there is a button generated from an ASP server control that should trigger a function in the code behind when clicked. However, I am encountering an issue where the functi ...

Optimizing Content Display for Android Screens

Although I have successfully optimized my site for OS and iOS, testing it on Android devices using browserstack.com has presented a challenge when it comes to targeting them with media queries. This is the query that I currently use for iOS devices: #uti ...

How to consistently hide a div with jQuery when a select option is changed

I'm encountering an issue with hiding a div using select and onchange function. Even though the jQuery function I've written is correctly showing and hiding the div based on select option values, when I revisit the page, the div is still displaye ...

Tips for adjusting the vertical position of an image within a bootstrap column by a small amount

Apologies in advance if this question has already been addressed, and I am struggling to adapt it to my specific scenario. My objective is to adjust the positioning of the two images shown in the screenshot example below so that they align with the grey b ...

Implementing jQuery UI toggleClass method to seamlessly alternate between two distinct CSS classes

My goal is to toggle between two CSS classes on a selector click using Jquery UI .toggleClass(), but unfortunately, it's not producing the desired toggle effect. $(".toggle").click(function () { $(".archivePosts .columns").removeClass( "l ...

Toggle the sliding menu drawer option (upward/downward motion)

When it comes to my simple menu, I'm using jQuery to toggle the visibility of a few DIVs. The code is straightforward as shown below, and I could really use some assistance with adding extra functionalities. <div id="one" class="navLinks"> cont ...

Utilizing jQuery to Showcase SQL Data

Within a PHP file, I am executing a query on my database to retrieve specific values from each newly inserted record in a table. By utilizing a while loop, the query fetches the data and displays it within a table that I have designed. Now, by employing j ...

Sticky positioning and outline effects

I have been working on creating a scrollable list with "sticky" headers. The functionality seems to be in place, but there are some visual glitches that I've encountered. The list itself is structured using a ul element styled with the Bootstrap 5 cl ...

Basic parallax application, failing to achieve the desired impact

My goal is to create a scrolling effect where the header text moves down slightly, adding some margin on top to keep it in view. I found the perfect example of what I want to achieve with the header text at this website: After spending hours working on i ...

Loading a page with a Chitika ad using Jquery can cause site malfunctions

I am experiencing an issue with my header.php file on my website. I included another PHP file for my ad code, but it seems to load the ad and then redirect me to a blank page. Can someone please review my code and let me know if there is an error? Thank yo ...

Tips for creating dynamic horizontal card layouts!

Check out my code here I've been struggling to create responsive horizontal cards that adjust properly on different screen sizes. Despite attempting to change the background image based on viewport size, I have not been successful. HTML <!DOCTYPE ...

Is there a way to ensure that an image stays pinned to the bottom of the screen, regardless of the device or screen

Looking for a solution to keep an image centered at the bottom of a website page regardless of screen size? I've tried different recommendations from Stack Overflow without success. position:fixed; bottom:0px; left:50%; Still struggling to make it wo ...

A step-by-step guide on dynamically updating the placeholder attribute of an element using a fed id

I'm completely new to jQuery and I have a feeling that I'm making numerous mistakes in my code. As part of a project, I am creating a small search page for esports teams. The user selects their team from the homepage, which is then transferred t ...