Steps to Delete a Table Row With a Cell Containing Certain Text

Here is the markup I am working with that includes

SPAN >> Table >> TR >> TD
:

https://i.sstatic.net/MnTCa.png

Now, I am looking to target and remove any TR element that contains a TD with the word "Question" inside a <nobr> tag. Can anyone provide guidance on how I can achieve this using CSS or jQuery? Thank you.

Answer №1

You have the option to utilize the filter method in order to compare the exact text within the <nobr> element, and then proceed to eliminate the nearest <tr>

$("span table tr td nobr").filter(function() {
  return $(this).text() === "Question";
}).closest("tr").remove();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span>
  <table>
    <tr>
      <td>
        <h3>
          <nobr>Question</nobr>
        </h3>
      </td>
    </tr>
    <tr>
      <td>
        Untouched
      </td>
    </tr>
    
  </table>
</span>

Answer №2

Combine the :has() selector with the :contains() selector to achieve your desired outcome.

$("tr:has(td nobr:contains('Text'))").hide();

See Example

Answer №3

Here is an example of how you can achieve this using jQuery:

$(document).ready(function(){
    $('td').each(function(){
        if($(this).find('nobr').text() === 'Question') {
            $(this).closest('tr').remove();
        }
    });
});

Answer №4

If you had provided the HTML code, I could have created a fiddle. Nevertheless, here is a solution for you to try:

Loop through the tr elements in the table and find the one that meets the condition


$("table.ms-formtable > tbody > tr").each(function(){
   var text = $(this).find("td:first").find("nobr").text();
   if(text === 'Question') {
      $(this).remove();
   }
});

http://jsfiddle.net/9tw2kfek/

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

Am I utilizing React hooks correctly in this scenario?

I'm currently exploring the example, but I have doubts about whether I can implement it in this manner. import _ from "lodash"; ... let [widget, setWidgetList] = useState([]); onRemoveItem(i) { console.log("removing", i); ...

Use jQuery to change the date format from Feb 17, 2012 to 17/02/2012

Here is the code snippet I am working with: let Date = "Feb 17, 2012"; Is there a way to transform it into Date = "17/02/2012" by utilizing jQuery? ...

Using regular expressions to extract substrings from URL

I have different URL routes, such as var url = '/product' and '/product/create'. Is there a way to use Regex in order to extract only the route name like 'product'? ...

The container div contains a pop-up that expands the height of the container, rather than overlapping on top

I am currently developing a grid system similar to Excel, but I am encountering issues with displaying pop-ups properly as the lower part gets cut off by the container div. This problem is reminiscent of a situation discussed in a Stack Overflow post titl ...

Can PurgeCSS be implemented with Next.js and module.scss files?

Is there a way to use purgeCSS with component level .scss files (filename.module.scss) in order to remove unused CSS? The hashed classnames make it tricky, especially in a next.js app that heavily relies on module.scss files for styling. This thread here ...

Modifying the color of a header through clicking on a specific anchor link

My goal is to create a fixed side nav bar on my webpage with an unordered list that links down the page using anchors. In addition, I want to dynamically change the color of an h2 element based on which item in the fixed nav bar is clicked on. For instan ...

Is there a way to customize the CSS ul menu specifically for the JavaScript autocomplete feature?

I have created a search page with autocomplete for the first textbox, but I noticed that the ul/li CSS classes used for styling the main menu are impacting the JavaScript list. How can I override the menu styling to display a regular list format? Being a ...

A guide on launching a Node.js application via the CMD command line, triggered by a separate .Net Core 3.0 application

Currently, I am working on a .NET Core 3.0 application and there is a need to initiate another Node.js application using the command line. Any tips on how to achieve this? C:\NodeApp>node app.js Your help is greatly appreciated! ...

The File Reader just informed me that parameter 1 is not in the form of a blob

When working with a file input in my React component, I keep encountering an error with the FileReader. Here's the specific error message: Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not o ...

Unable to retrieve information from the openweatherapi

I am currently working on developing a basic Weather App, and I have chosen to utilize the jQuery Ajax method to fetch data from openweathermap. The function I am using to retrieve the data is as follows: $(document).ready(function(){ $('#submitWeath ...

What is the best way to make sure the background image adjusts to fit the browser window as it is resized?

Currently, I am working on creating a small responsive webpage that features a background image with several buttons placed on top of it. To set the background image, I included the following CSS: .background { height: 100vh; width: 100%; backg ...

Explore how Next.js's getServerSideProps feature incorporates loading animations and improves

I have implemented getServerSideProps in my project's pages/post/index.js file: import React from "react"; import Layout from "../../components/Layout"; function Post({ post }) { console.log("in render", post); return ( <Layout title={pos ...

Swapping out the content of an HTML element with different text using JavaScript

UPDATE:(below) I have developed a web application that features a template for displaying various books retrieved from the server using Python (Flask). The information about each book, including titles, IDs, and authors' names, is stored in the varia ...

The issue with the table inside a bootstrap modal is that it is not properly sized and does

I am facing an issue with a modal that has two columns. One of the columns contains a table which is too wide and requires horizontal scrolling. I need help to make the table fit into the column without any scrolling problems. The table should be able to s ...

Having trouble rendering the index.ejs file in NodeJS, as it keeps serving the index.html located in the public folder

I am facing an issue where the code I have written is still displaying the index.html page from the public folder, but I actually want to render the index.ejs file. I have followed a video example, so I'm not sure why the instructor is able to render ...

Maintaining optimal frames per second using three.js

When using a WebGLRenderer instance with antialias = true, performance problems become evident as the resolution increases, particularly on retina displays (window.devicePixelRatio === 2). As it is not feasible to switch antialiasing modes dynamically, th ...

Having difficulty making my directive function in Angular

I'm encountering an issue with my directive not working properly. I suspect that I may have registered it incorrectly, but I can't seem to figure out the mistake. Could it be related to the naming convention? Here's the code snippet in quest ...

unable to detect image input type

My dilemma lies in trying to submit a form using an image input type. The ajax request works as expected, and I receive a response from my php script. However, I encountered an issue where the image button was not changing its image upon submission. Accord ...

Transforming nested tables into JSON format

I have a table that is dynamically generated and I am looking to convert it into JSON format. Despite trying several methods, I haven't been successful. Can someone help me by providing guidance on how to achieve this using jQuery? For your reference ...

prompting the JavaScript hangman game to identify the letters in the "selected word"

Currently, I am on a mission to teach myself Javascript and have taken on the challenge of creating a simple hangman game. This type of project is commonly used in interviews or tests, so it seemed like a great opportunity for practice. My approach involve ...