Apply the Jquery class to only one row instead of multiple rows

Situation: my issue is quite straightforward.

The class input-test is being applied to multiple rows.

This class should only be applied once in the row I am editing. Currently, when I click on multiple rows to edit, the class input-test is applied, which should not happen.

To Test:

Click on the edit button in table 1

JSFiddle: http://jsfiddle.net/f7debwj2/56/

JQuery:

$(document).ready(function() {
    // jQuery code goes here
  });
  

Answer №1

When using the line:

$('#example tr td:nth-child(2) input').addClass('input-test');

it adds the class to all columns on every row.

If you only want to target a specific column, you can either filter the selection or specify the context of the element you've found, like this:

$(ctrl).closest("tr").find("td:nth-child(2) input").addClass("input-test");

This code takes the previously located ctrl element, moves up to its containing row, and then applies the class only to the desired cell and input within that row.

If you need to remove the input-test class from other rows, you can also include:

$(".input-test").removeClass("input-test");

Depending on your preference for single select or multi-select behavior.

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

What is preventing me from navigating to other pages in my React application?

Recently, I have been experimenting with ReactJS and encountered an issue where I couldn't access my other pages. The code snippet provided below seems to be the root of the problem. I am in the process of developing a multi-page application using Re ...

Requesting the current URL with jQuery's $.get method

I am attempting to make an ajax call using the $.get method like this: jQuery.get('www.example.com/some-url?q=node/09090&dest=example', function(result) { console.log(result); }); Interestingly, even when I intentionally leave the url par ...

Using jQuery to send LocalStorage data to an email address with the help of PHP

Currently, I am in the process of developing a basic eCommerce/checkout system. My goal is to utilize localStorage data and transfer it to PHP using jQuery or any other method that is convenient. However, when I attempted to send the email, I only received ...

Implementing a collapsible full-width button that contains multiple elements (Bootstrap)

I am currently in the process of developing a responsive calendar that will display additional information in an expandable "well" when the user clicks on a specific event. My goal is to have the button, date, and icon all appear on the same line at full ...

Learn the process of using Angular Js to compare checkbox values with stored comma-separated values in a database

When displaying amenity checkbox options using ng-repeat of a JSON array and saving them into the database as comma-separated IDs like "1,3,7" within a single string, the challenge arises when needing to edit the amenities. This is due to retrieving the ex ...

What is preventing jQuery 3 from recognizing the '#' symbol in an attribute selector?

After updating my application to jQuery 3, I encountered an issue during testing. Everything seemed to be working fine until I reached a section of my code that used a '#' symbol in a selector. The jQuery snippet causing the problem looks like th ...

Upon being provided with a route param, the response will be

For my current project using Express, I want to implement Reddit-like functionality where appending ".json" to any URL will return JSON data instead of the rendered template. To set up the rendering engine in Express, I am using Jade. Here is how I config ...

Changing a jQuery component into an Angular 2/4 component - is it possible?

Currently, I am diving into the world of Angular and working on developing a test application for practical experience. During my research, I stumbled upon an amazing "user card" design that utilizes jQuery and Google Material color palette. My goal is to ...

Is it possible to incorporate a jQuery widget within a table?

Can the jQuery sortable widget be utilized within a table, or is it designed to function separately? Here is the link to the jQuery widget for reference - http://jqueryui.com/sortable/#default ...

What is the best way to eliminate the "0"s from the center of items within an array?

I have developed a table sorter that handles columns containing both letters and numbers, such as "thing 027". To facilitate sorting, I prepended zeros to the numbers. However, I am now looking for a cleaner way to remove these zeros from the numbers using ...

Creating a string specifically for implementing regular expressions in JavaScript

I'm currently working on a custom jQuery plugin known as jQuery-Faker. This plugin is designed to produce fake data for populating form fields based on their respective field names. One of the tasks I have set out to accomplish is generating phone num ...

When using Node.js and geth together, running JavaScript code may lead to the creation of zombie processes, causing the

Currently, I am utilizing a JavaScript code that connects to the web3 package on Ethereum's JSON RPC API. This code is designed to iterate through each transaction in an incoming block. If the transaction involves an internal wallet, it sends the rele ...

Enhance the "text" attribute of IXMLDOMElement to enable functionality in Chrome

The web application I am currently working on was developed approximately 10 years ago and is only compatible with Internet Explorer. My goal is to make it functional in Chrome as well. I am facing a challenge regarding the "text" property of IXMLDOMEleme ...

Using AngularJS to send a post request with cherrypy

I am facing an issue with posting events into a CherryPy small application that responds to GET/POST requests. When attempting to do so using AngularJS, nothing gets posted. I'm unsure if the problem lies with AngularJS or CherryPy (CP). Cross-domain ...

Arrange elements prior to the treeview within the unordered list/ list items

Below is a snippet of code that I am working with: <ul> <li>group 1 <ul> <li>group 1.1</li> <li> group 1.2</li> <li>group 1.3 <ul> <li>group 1.3.1</li> <l ...

Designing a flawless CSS pattern for the online world

Currently, I am working on creating a seamless CSS pattern for the web. Even though this may seem impractical and nonsensical, I find joy in experimenting with it. View my progress here After successfully designing my first tile, my next challenge is to ...

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 ...

A guide on crafting a test scenario for an AngularJS controller using the Jasmine framework

I recently created an angular module called userModule.js 'use strict'; angular.module('users', ['ngRoute','angular-growl','textAngular','ngMaterial','ngMessages','ngImgCrop', ...

When attempting to use AJAX to send an object from JavaScript to PHP on the same page, I encountered an issue where, instead of receiving just the object, the entire HTML page was being returned

When I make a POST request, instead of receiving the object as response data, I am getting the entire HTML page back. This is causing me to be unable to retrieve the object in my PHP script. //Here we have an example of the object, not the actual object ...

Focusing on animation and keyframes within individual div elements

I encountered an issue while trying to add hover functionality to pause my pure CSS slider. Initially, I had the pausing feature working but then I wanted to include a div displaying that it is paused. However, I realized that one element cannot trigger an ...