$(document).ready(function() {
$(".table tr:odd".addClass("highlight");
// .....
}
I've got some HTML
code for a table with 4 rows, and I've defined a CSS
class to alter the color of the odd rows. Appreciate any help you can provide.
$(document).ready(function() {
$(".table tr:odd".addClass("highlight");
// .....
}
I've got some HTML
code for a table with 4 rows, and I've defined a CSS
class to alter the color of the odd rows. Appreciate any help you can provide.
Suppose you have a snippet of HTML structured like this:
<table>
<tr></tr>
<tr></tr>
<tr></tr>
</table>
Consider implementing the following solution:
$(document).ready(function() {
$("table tr:odd").addClass("highlight");
});
Seems like a simple mistake, just forgot to close the bracket
$(document).ready(function() {
$(".table tr:odd").addClass("highlight")
^
|
I assume you intended to close the DOM ready handler in your example.
A more concise alternative would be:
$(function() {
$(".table tr:odd").addClass("highlight")
});
Both of these solutions are based on the assumption that your HTML includes a table
with the class attribute set to "table" on the table
element:
For example:
<table class="table">
<tr></tr>
...
<tr></tr>
</table>
@ Jeffrey Kola Abodunde It seems like there is a small error in the code snippet you provided.
Summary of jquery syntax
In jQuery, the object symbol is represented by $
The element on which effects are to be applied is selected using $(".table tr:odd")
The effect to be applied is addClass
Therefore, your corrected code should look like this:
$(document).ready(function() {
$(".table tr:odd").addClass("highlight")
});
You seem to have missed a closing bracket before the addClass method was called.
if you grasp the essence of your question:
$(document).ready(function() {
$(".table tr:odd").addClass("highlight")
}
It should be like this:
$(document).ready(function() {
$(".table tr:odd").addClass("highlight");
});
However, I believe you intend to reference the element you are currently referring to the table class, which may not exist.
Therefore, it would need to be:
$(document).ready(function() {
$("table tr:odd").addClass("highlight");
});
If you have multiple tables on your page, you will target all tables. I suggest providing an id for that specific table, so you only target that table
$(document).ready(function() {
$("table#tableid tr:odd").addClass("highlight");
});
I hope this helps and good luck!
How can I extract the href link from the .image1 div class? <div class="image1"> <a href="/images/productA.jpg"> </a> </div> Then, how do I insert it into the image src shown below? <ul class="example"> <li class ...
I need help achieving a layout similar to the image linked below: https://i.sstatic.net/GTOJF.jpg In my design, the red box represents my company logo with some text hidden. However, in my attempt shown in the second image here: https://i.sstatic.net/7xY ...
I'm currently working on developing a Chrome extension that will display tweets featuring the hashtag perkytweets within the extension's popup. However, I'm facing an issue where nothing is being displayed. Let's take a look at the cod ...
When using promises, do I need to explicitly return the resolve and reject methods? The code runs smoothly for single condition statements, but what happens if there are multiple conditions - will reject and resolve automatically end or do we need to use ...
When a word is entered in the textarea, it should be assigned to a specific class within an 'ol' tag. Each subsequent word will be placed in the next class sequentially. If there are no more words, the remaining classes should remain empty. <! ...
My application generates numerous elements dynamically based on server data in JSON format. This process involves embedding a significant amount of HTML directly within my JavaScript code, leading to pollution and making it increasingly challenging and l ...
<div className="col-span-3 h-screen overflow-y-scroll "> <ul className="m-5"> <li className="flex items-center mb-4"> <FontAwesomeIcon icon={faRss} classNa ...
Recently on my HTML website, I encountered an issue where I tried adding a transparent image over a button but found that I was unable to click on the button afterwards. The problem seems to be related to the following code snippet: #container { heigh ...
I recently tried to perform a patch request on an HTML form from the frontend to MongoDB database through a NodeJS API. Below is the structure of my Nodejs API: app.route("/requests/:rollno") .get(function(req, res) { // get method to find a q ...
Recently, I've been encountering issues while attempting to upload images to a Dropbox app folder using the Dropbox API v2 within my node.js backend. Unfortunately, every image that successfully uploads seems to be corrupted and ends up being only 15 ...
I'm trying to figure out how to make a div expand to a certain point and then wrap to the next line after reaching 200px. Currently, both the div and span are positioned absolutely in my element structure: <div><span></span>My text ...
My website has a form for entering dummy patient information, with a table to display the submitted data. However, I'm facing an issue where the data is not being stored in the array when the user clicks the "Add Patient" button. Upon checking the arr ...
Can anyone help me set a placeholder for a horizontal login form in Drupal 7? I want the placeholder text to disappear when clicked on, and I want it to display 'username' and 'password'. Here is the current code for the form. Thank you ...
Greetings, I am encountering a font-face issue specifically in Chrome on Windows. Below is the code snippet causing the problem: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta ...
Here's the code snippet I've been working on: const express = require('express'); const router = express.Router(); const WooCommerceAPI = require('woocommerce-api'); const WooCommerce = new WooCommerceAPI({ ...
Recently, I followed a tutorial on how to submit a form without refreshing the page using jQuery. Instead of using PHP as recommended in the tutorial, I decided to create my own classic ASP page. However, I encountered a problem - when I try to input space ...
I am trying to retrieve the client's local IP address within an internal network using Angular. This data will be sent to an IP address within the network without requiring authorization. I have searched extensively online but have only found methods ...
Handling a large XML file (~1.5gb) in Node Js by streaming it to process data in chunks has proven challenging due to the complexity of the documentation. A simple code snippet I am currently using is: var fs = require('fs'); var stream = fs.c ...
My goal is to create a number counter that can either count up or down, such as from 1 to 100 or from 100 to 1. While I have come across several plugins that offer this functionality, they all contain a duration variable that dictates how long it takes to ...
Is there anyone who can provide insight into how to establish this validation pattern? All sentences must start with a capital letter, and the message should conclude with a full stop. There should be no spelling errors. ...