How to create a bottom border in several TD elements using a combination of CSS and jQuery

Check out my Website: Search Page

I have written some CSS that functions well when searching by Name, but not by Specialty:

.displayresult {
    display: block;
}
#fname, #lname, #splabel, #addlabel, #pnlabel {
    border-width: 4px;
    border-bottom-style: double;
}
#first, #last, #specialty, #address, #phone {
    border-width: 4px;
    border-bottom-style: double;
}

When a user selects specialty and an option, the CSS only adds a double border on the last TD.

How can I adjust the CSS or jQuery Script to achieve one of the following options:

  • Add border after each TD?

OR

  • Alternate between white and grey TDs?

I attempted using jQuery as shown below, but it did not work and behaved the same as the CSS:

$("#fname").css('border-bottom-style', 'double');

You can check out the demo at the link provided above.

Answer №1

To create alternating white and gray backgrounds for each TD element, use the following CSS:

td:nth-child(odd) {
    background-color: gray;
}
td:nth-child(even) {
    background-color: white;
}

Try out the DEMO here!

Answer №2

It is important to remember that IDs should be unique and only assigned to a single element in the DOM.

If your code is not functioning correctly, it might be because you are treating the ID #fname as if it were a class.

Instead of using <td id="#fname">, try using <td class="fname"> for better results.

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

Transferring data using a JavaScript enhanced form

I'm currently working on a search page that showcases results in a table format. I am looking to enhance the functionality using Javascript. The table is contained within a form, and each row offers multiple actions, such as adding a comment. While I ...

Error encountered using jQuery $.post: TypeError - e.type is not a valid function

I'm currently in the process of developing a feedback script specifically for the ZetaBoards forum software. My approach has been to create a $.post function, but when I attempt to submit the form by clicking the submit button, all I get in return is ...

Utilizing Pseudo Classes in Custom Styled Components with MUI

Exploring the world of React and MUI styled components for the first time. Currently, I'm delving into grid layouts and trying to style all children of a specific component. My goal is to target ${Item1}:nth-child(3n-1), ${Item2}:nth-child(3n-1), ${It ...

How to dynamically deactivate dates in a jQuery datepicker

For my current project, I need to implement a feature where the user can select a hotel, arrival date, and departure date. Upon selecting the hotel, I have to display the unavailable dates of the hotel in the jQuery datepicker as disabled. This is the Jav ...

Make the height of each div animate individually

I'm looking for a solution to animate multiple divs individually without using a class or id. Let's say we have 10 divs and I want to set the height of each div based on specific percentages. One option is to assign random heights to each div li ...

Incorporating a dynamic fill effect into an SVG pie chart

I am looking to animate a pie chart with a variable value that is unknown upon loading. Assuming I fetch the value promptly and convert it into a rounded percentage : var percentage = Math.round(sum * 100 / total); Next, I place this value here : <di ...

Excessive image display | HTML and CSS synergize

I am having some trouble with my image gallery. Each image is displayed as a vertical column and has zooming effects when hovered over. Clicking on an image should show it in full screen with a caption. The problem arises when dealing with images that are ...

Ways to manage an element that has been loaded using the load query function

After implementing the query load function to update posts on the homepage, I was able to display the most up-to-date posts. However, a new issue arose: Whenever I updated all posts without refreshing the entire page, I needed a way to control the element ...

Could use some assistance in developing a custom jQuery code

Assistance Needed with jQuery Script Creation <div>Base List</div> <div id="baseSection"> <ul class="selectable"> <li id="a">1</li> <li id="b">2</li> <li id="c">3</li> ...

What is the process for translating symbols in a URL or text into hexadecimal characters? (e.g. changing = to %3D)

Currently, my script in use is extracting variables from URL parameters using jQuery. The value it retrieves happens to be a URL. For instance, if the URL is as follows: http://localhost/index.html?url=http://www.example.com/index.php?something=some the ...

Set boundaries for the width and height of an image in the input field

Looking to restrict the size of an image in an input field using HTML, CSS, and JavaScript/jQuery. Goal is to maintain a perfect square aspect ratio for profile photo uploads (for example, 200x200 or 300x300). ...

"Unraveling the depths of a multidimensional array in JavaScript: a comprehensive guide

Seeking assistance from this wonderfully helpful community :) It seems like I might be declaring and creating my arrays incorrectly, as I am trying to add content to an array of arrays but unable to retrieve anything from it. Here's the code snippet ...

The Jquery Ajax call is prompting the download of a JSON file instead of entering the success block

I have been facing an issue with uploading an excel file to a database in MVC5. The upload process is successful, after which the uploaded data should be displayed. I am trying to achieve both of these actions within a single action method. public ActionR ...

Adjust the cell color for AgendaWeek view only in the full calendar

I am looking to modify the cell color of my full calendar specifically in AgendaWeek view. I have come across some solutions that only apply to basicWeek view. Can anyone provide assistance? Currently, the following event successfully changes the month vie ...

Animating images with Jquery

As a beginner in Javascript and Jquery, I am currently learning about image animation. However, I have encountered a question regarding moving an image from bottom left to top right within the window. Is there a more efficient way to achieve this compared ...

The form failed to be submitted even after undergoing ajax validation

Although this question has been asked many times before, I am still confused about where I went wrong. My goal is to validate a form using ajax and submit it if everything checks out. Below is the code snippet that I have been working with: ...

Transform the json structure into a different json layout

I am struggling with converting a JSON file from one format to another as I am new to JSON. Here is the initial JSON structure that needs to be converted: { "message": "Successfully Advisor data has been fetched.", "success": true, "data": { ...

Stop using Flexbox in Material UI on small screens

How can I prevent Flexbox from functioning on small screens using Material UI? I am looking for something similar to the d-md-flex class in Bootstrap but for Material UI. In Bootstrap (works as expected) <div class="d-md-flex align-items-md-center ...

JSON does not transmit data via post requests

I have a question regarding JSON. Initially, I created this jQuery code: <script> $('#buy').click(function(){ var items=[]; var item={ firstname:'blabla' ...

I am looking for a way to generate unique dynamic IDs for each input textbox created within a PHP while loop. Can

How can I retrieve the ID of a selected text box generated within a while loop in order to update a field similar to phpMyAdmin? <?php while($row=mysql_fetch_assoc($result)) { ?> <tr> <td><input type ...