Is there a way to bypass the initial result when using document.querySelectorAll?

this is my own unique html content

<div class="content-body">
<table style="text-align:center;" class="table table-bordered">
<tbody>
<tr>
<th>Text Line</th>
</tr>
<tr>
<td>1111111<br>2222222<br>3333333</td>
</tr>
</tbody>
</table>
</div>

about this issue :

var text = document.querySelectorAll('.content-body');

will display the output in the following form :

Text Line
1111111
2222222
3333333

If you aim to exclude the title line: Text Line

and only retain the resulting lines as follows:

1111111
2222222
3333333

got any solutions?

Answer â„–1

If you want to target all the <td> elements, you can use the following code snippet:

document.querySelectorAll('.modal-body tr td').forEach(item => console.log(item.innerText.split('\n')))
<div class="modal-body">
  <table style="text-align:center;" class="table table-bordered">
    <tbody>
      <tr>
        <th>Line</th>
      </tr>
      <tr>
        <td>aaaaaaaaa<br>bbbbbbbbbb<br>cccccccccc</td>
      </tr>
      <tr>
        <td>aaaaaaaaa<br>bbbbbbbbbb<br>cccccccccc</td>
      </tr>
    </tbody>
  </table>
</div>

Answer â„–2

Here is just one of the many strategies you can use to complete this task, while also gaining valuable coding knowledge.

let doc, html, bod, M, I, S, Q; // for use on other loads
addEventListener('load', ()=>{
doc = document; html = doc.documentElement; bod = doc.body;
M = tag=>{ // make element
  return doc.createElement(tag);
}
I = id=>doc.getElementById(id); // get by id
S = (selector, within)=>{ // get first by selector
  let w = within || doc;
  return w.querySelector(selector);
}
Q = (selector, within)=>{ // get all by selector
  let w = within || doc;
  return w.querySelectorAll(selector);
}
// magic under here - tiny Library above
const tdWithText = S('.modal-body>table>tbody>tr>td');
const resArray = tdWithText.innerText.split(/\n/);
console.log(resArray);
// resArray[0] is a line - resArray[1] is b line - resArray[2] is c line
}); // end load
table{
  text-align:center;
}
<div class='modal-body'>
  <table class='table table-bordered'>
    <tbody>
      <tr><th>Line</th></tr>
      <tr><td>aaaaaaaaa<br>bbbbbbbbbb<br>cccccccccc</td></tr>
    </tbody>
  </table>
</div>

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

The child component's useEffect is not triggered when rendering the parent component with the <Link> element

I am facing an issue with my parent component that contains a child component. I have set up a route for the parent component in the main app and now I need to access this parent component from another page using the Link component. However, I am encounter ...

What is preventing d3.json from including cookies in the request?

I'm delving into the world of ajax requests with d3.js (v5) and I'm facing a little hiccup. Here's my code snippet: d3.json(uri).then(data =>console.log(data)); When I tried this in an app utilizing cookie authentication, I consistently ...

css table cells with overflow

I need help with a table where I have text in one of the td cells that goes beyond the right border and wraps to the next line. What I want is for the overflowing text to be hidden when it reaches the border, showing only the last 3 visible characters repl ...

Transaction response for embedded iFrame with Accept.js on Authorize.net

I've recently integrated authorize.net accept.js embedded iFrame into my application, but I'm facing difficulties in setting the transaction response in my lambda function to retrieve the expected data. Although I've checked similar queries ...

Tips on building a blog using solely index.html, style.css, and script.js files

Looking for inspiration for blog listing pages? Check out some examples like: HubSpot's marketing blog or iGoMoon's blog. I'm trying to figure out where I should start. Should I begin with the first line of code? Or can I import sample code ...

Is it possible to derive the language code without using the Common Locale Data Repository from a rough Unicode text

I am currently developing a dictionary application. One of the features I am working on involves identifying the language of a Unicode character when entered by a user. For example: 字 - would return ['zh', 'ja', 'ko'] ا٠...

Is there a way for me to discover the identity of the victor?

There are 4 divs that move at different, random speeds each time. I am trying to determine which one is the fastest or reaches the goal first. Additionally, there is a betting box where you can choose a horse to bet on. I need to compare the winner with my ...

The div structure generated through JavaScript appears distinct from its representation in the live DOM

Currently, I am facing a challenge with creating a complex nested Div structure within a JavaScript loop that iterates over JSON response objects from the Instagram API. The main goal is to set the URL for each image within a specific Bootstrap div layout. ...

What is the best way to align an equal number of divs in each row?

I need help arranging my divs in rows, with 3 divs in each row. Can someone assist me with this? Here is the code I have written so far: .container { display: flex; flex-wrap: wrap; } .item { border: 2px solid black; width: 100px; height: 10 ...

What is the process for retrieving tags and attributes from a website using nodejs?

In my project, I am looking to extract the metatag and specifically check for the presence of 'viewport' within the metadata using nodejs. Despite my efforts in searching, I have not been able to find a highly effective solution. Does anyone have ...

Having trouble getting the Vue.js framework to function properly on a basic HTML page with a CDN implementation

I recently delved into learning vue.js and decided to focus on forms. However, when I tried to open the file using a live server or XAMPP, it didn't work as expected. It had worked fine before, but now I seem to be encountering some issues. Could anyo ...

The "results per page" ajax dropdown in Yii stops working after other ajax content is loaded on the page

One of the views in Yii framework is the "Patients" view, which contains several CGridViews and other elements that are loaded via ajax after the initial view has loaded. Some of these elements are nested within multiple levels of ajax-loaded divs. Within ...

The initial state in NextJS fails to update when routing to the same page with different parameters

This particular project utilizes NextJS The structure of my page's URL is as follows: localhost:3000/first/second When I invoke getInitialProps on this page, the data retrieved from it is passed to the component and used to set the initial state li ...

Resolving Problems with Ion-Split-pane in the Latest Versions of Angular and Ionic

There seems to be a perplexing issue with the ion-split-pane element that I just can't wrap my head around. Once I remove the split-pane element, the router-outlet functions perfectly fine. The navigation is displayed after a successful login. The on ...

Preventing parent requests from being triggered when a child element is clicked in Angular 2

I have a similar code structure as shown below and I am trying to achieve the behavior where clicking on the Child Div does not trigger the Parent Div click event. <div class="parentDiv" (click)="parentDiv()"> <div class="childDiv" (click)="ch ...

Is there a way to handle the completion event of jQuery's .tmpl() method?

Can someone guide me on how to create a $.tmpl ready function? In my code, I send the ajax json to my createForm function. var doFunction = { new: function() { $.ajax({ url: 'index.php?...', success: function(data) { cr ...

Is your Ajax jQuery live search not functioning properly with JSON data?

My programming code is not functioning properly. Here is the file I am working on. When it does work, it does not display the list and gives an error in the Json file. I am unsure of the reason behind this issue. You will be able to view the error in the C ...

The feature in DataTables that allows users to choose how many items to display per page is not functioning correctly

My DataTable is experiencing issues with the box that allows you to select how many items per page you want to show. Instead of displaying just the numbers, it shows: [[5,10],[5,10]]. I have tried to troubleshoot this problem without any success. Addition ...

Leverage CSS styling for database values within a PHP framework

How can I style MYSQL database values in HTML using CSS? My vegetarian database row has 'Y' for yes and 'N' for no. I want to apply different styles to these values using CSS as I display them on my PHP-based page. if ($result1->num_ ...

Animating CSS when closing a modal box

I followed the instructions from a tutorial on W3Schools here to create this code. The "open model" button triggers the modal to open with a smooth CSS animation, which looks great. However, when I click the close button, the modal abruptly closes without ...