Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to obtain the value 100 (from the displayed "100 meters" which appears on the webpage below)
from these related/sibling div tags/nodes:


<div class="parameter">
  <div class="parameter-value"> 100 </div>
  <div class="parameter-measure-unit"> meters </div>
</div>


This means:

1. Uniquely identify the 2nd child div with parameter-measure-unit

2. Uniquely identify its sibling / sister div with parameter-value (as the first child div)

3. Extract the text ("100") from this sibling div.

What I have tried:

I'm still researching between CSS and jQuery selectors.
The ::text selector is deprecated.

I would consider XPaths as well.
Posted
Updated 28-Jul-21 6:37am
Comments
SeeSharp2 26-Jul-21 10:15am    
Here is the list of jquery selectors. There are a lot.

https://api.jquery.com/category/selectors/
s_qa 12-Aug-21 6:35am    
Please remove this comment.
Finding documentation is a prerequisite for asking a question.
I've been there on that link.
SeeSharp2 12-Aug-21 7:01am    
Well, that link has your answer so why are you asking us for help if you've already seen that link? You have to use a combination of selectors and those are all the available selectors. Pick the right one.

1 solution

It's not entirely clear what you're trying to do.

If you're starting from the <div class="parameter-measure-unit"> and want to get the <div class="parameter-value">, all you need to do is:
JavaScript
let $unitDiv = ...;
let $valueDiv = $unitDiv.closest(".parameter").find(".parameter-value");
.closest() | jQuery API Documentation[^]
.find() | jQuery API Documentation[^]

Or alternatively:
JavaScript
let $valueDiv = $unitDiv.prevAll(".parameter-value");
.prevAll() | jQuery API Documentation[^]

If you're starting from the <div class="parameter">, you can get both children with:
JavaScript
let $parameterDiv = ...;
let $valueDiv = $parameterDiv.find(".parameter-value");
let $unitDiv = $parameterDiv.find(".parameter-measure-unit");
 
Share this answer
 
Comments
s_qa 12-Aug-21 6:38am    
I think it is, because you solution tends towards the answer to what I was trying to do.
However, please try to use only selectors (advanced ones) and no JS code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900