Enhance JQM Styled Element with an Extra Class Using JQuery Mobile

My goal is to include a class in JQM's list divider <li>'s:

<li data-role="list-divider" role="heading" class="ui-li ui-li-divider ui-bar-e ui-first-child">A</li>

I have attempted to accomplish this by utilizing JQuery within the HTML document:

<script type="text/javascript">
document.addEventListener("deviceready", function(){
$('.ui-li-divider').addClass('customClass');
});
</script>

However, it appears that the class is not being added to the element at all. Upon inspecting the element in my browser, I do not see customClass included.

Is there a proper method to achieve this without delving into the core functions of the JQM library?

(Please note: the stylesheet containing cusomClass is linked below the JQM stylesheet)

Answer №1

Check out this demonstration at http://jsfiddle.net/yeyene/5kfnT/4/. Test the commenting feature and toggle the .addClass script to observe the effect.

Implement the .each() function for optimal results.

JQUERY

$(document).ready(function(){
    $("ul .ui-li-divider").each( function () {
        $(this).addClass('customClass');
    });
});

Your CSS

.customClass {
    background:red !important;
}

Screenshot

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

Load the entire contents of a div asynchronously

Currently, I am attempting to load the contents of an entire div asynchronously. At the moment, I am preloading only the background images in the div .orbit-wrapper. My goal is to defer loading everything in that div until the page has completely loaded. ...

Navigating through directories in an HTML file

In my directory, the folders are named in uppercase letters and have the following structure: ONLINESHOP |-- index.html |-- COMPONENTS |-- CONFIG |-- TEMPLATES |-- CSS |-- main-style.css |-- CONTROLLERS |-- MODE ...

Exploring the power of DOM manipulation in both jQuery UI and AngularJS UI Router

I have a query regarding the integration of jQuery UI and AngularJS UI Router. My aim is to incorporate jQuery UI themes into my application, however, when using AngularJS UI Router, I face issues with an incomplete DOM tree. Is there a way to successfull ...

The latest grid system in Bootstrap 5 is designed to streamline

I'm attempting to use Bootstrap 5 to create a grid system similar to the image shown below View Image I've been struggling to replicate the grid section shown in the attached image using Bootstrap 5. <div class="container-fluid"> ...

Managing the sequence of QUnit tests

I have created a website using jQuery and made numerous ajax requests in JSON format. I am interested in performing unit tests to validate the server side requests. Since I used jQuery, I chose qUnit for testing, but I'm facing an issue with the order ...

Issue with validation not being displayed for select element when both the uniform and validation plugin are applied

I have been encountering an issue with the Inline Form Validation Engine 2.6.1 jQuery plugin when using it in conjunction with the Uniform UI jQuery plugin. While the validation message displays correctly with input text boxes, it does not show up for sele ...

A guide on extracting data from an HTML table containing various input fields

I have a webpage with this table generated by a PHP script. What I need to do is extract the values from each of the 4 input fields and save them in separate JavaScript variables. Each button already has an onclick="fetchGrades(); trigger added. How can ...

Instructions for inserting an alert message into a Bootstrap div when a user submits an incorrectly filled-out form

I am looking to use jQuery for validating user input in a form. I managed to get the validation working, but when I try to display the errors in a div written in my .php file, it doesn't work properly. The errors are only displayed for a few seconds a ...

How can I incorporate margins or adjust scaling within dompdf?

After creating a PDF using dompdf with the paper size set to A6, I am experiencing issues when trying to print it on A4 and letter paper sizes. The left and top borders are being cut off. Is there a way to generate a PDF that is compatible with A4, A6, l ...

Is there a way to get Axios to display CSS on the page?

While working on a Web Viewer project with axios for web scraping practice, I encountered an issue where the CSS wasn't loading properly. Here is the code snippet I used: console.log("Tribble-Webviewer is starting!") const express = requir ...

The issue with the second child of the nested datatable in Jquery is not

Within my project, I have implemented a jQuery nested datatable which includes two child rows for each row. Below is the code snippet that demonstrates this: $(function(){$(document).on('click','#tab td.control', function(){ var ...

I'm looking to validate an input tag in HTML5 using JQuery. Can anyone help clarify this process for me?

New to JQuery and struggling with HTML5 input tag validation. On my page, I have an input tag like this: <input id="variazioneAnticipo" class="rightAlligned form-control" style="width:50%" type="number" step="0.01" /> and a button: <button id="va ...

Overlapping text effect with CSS

Currently, I'm in the process of building a website using HTML5 and CSS3. One particular challenge I've come across is when trying to integrate two CSS images together, with one containing a few lines of text. Let me get straight to the issue at ...

Make sure to maintain the hover effect even after clicking

How can I make my div retain the hover effect even after clicking on it? Here is the code snippet: #work_btn{ position:absolute; top:60%; left:60px; color:grey; background: -webkit-linear-gradient(0deg, #ff956c, #ff3644); -webkit-background-clip: text ...

"Switching to a new request in jqgrid will automatically cancel the current

I am using a jqgrid on my website to display data in JSON format retrieved from the server. The grid includes some blank cells which users can double-click on to update the data. However, I have encountered a problem where if I click too quickly on multipl ...

How can I ensure that changes made to a div in ASP.NET remain persistent during postback?

My current setup involves using jquery to toggle a div on and off successfully. However, I am encountering an issue where any changes made are not saved when a postback occurs on the page. Can anyone provide guidance on how to save these changes? Any assis ...

Spread out the items within an inline block

Is there a way to create space between icons that are in an inline block without them touching each other? One solution could be to add a container around each icon, center the icons within the containers, and then place the containers in the block. You c ...

What is the correct way to unbind and rebind multiple URL loads in jQuery Ajax?

Using Ajax, I populate a SELECT element with a list of brands. Then, I retrieve the selected value (brand id) and use it to load another SELECT with templates for the chosen brand from a different Ajax URL. Below is the code snippet: $(document).ready( f ...

detecting key presses on documents using javascript

I'm having trouble capturing document-level key press events on a webpage. I've tried using the following code: $(document).bind('keydown', 'a', keyevent_cb); It works fine in IE, but it's not consistent in Firefox. I&a ...

When converting HTML to PDF using Dompdf, Font Awesome icons may not appear as expected

I am currently using Dompdf for exporting an HTML page to PDF. The issue I am facing is that when the HTML file contains Font Awesome icons, in the resulting PDF there are question marks instead of the icons. Below is a snippet of the HTML code: <!DOC ...