A
A
Alexey1002019-02-04 08:33:21
linux
Alexey100, 2019-02-04 08:33:21

How to get nearest parent with unique selector?

Hello.
Can you please tell me how to get a unique parent in native js? For example, for the li
element , the unique parent will be .second_block And for #text , the unique parent will be body

<body>
<div class='content'>
   <p id='text'>some text</p>
</div>
<div class='second_block'>
   <div class='content'>
      <p>some text 2</p>
      <ul>
         <li>list 1</li>
      </ul>
   </div>
</div>
</body>

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Danil Biryukov-Romanov, 2016-07-04
@urtow

Hetzner changes the screws for one of the following reasons:
a) The screw is not visible in the system. Moreover, it is desirable to check the same screw in the rescue mode at the beginning - if it is not visible in the same place, then everything is ok.
b) Screw failed the smart test. That's exactly what it says - test failed.
c) There are reading errors on the screw. You can see them in the dmesg output:
blk_update_request: I/O error, dev sda, sector 1937033224
Just do it
and if it shows something, then your disk is dying.
Smart degradation is not proof that the disk needs to be changed for Hetzner

N
nikolayvaganov, 2016-07-05
@nikolayvaganov

1. Monitor your smart daily and run long and short tests daily.
2. If you have a seagate barracuda (as far as I remember, they put them), then make daily backups somewhere outside. At hetzner 3Tb, the seagates usually die immediately in pairs.
3. Load into rescue and check them with software hardware (disks)

R
Rsa97, 2019-02-04
@Rsa97

In a loop, iterate up the element's parents and check each one for "uniqueness".
For id, everything is simple, if there is an id, then it is unique.
It's also easy for a tag, getElementsByTagName and check the list for the number of elements.
Worst of all for classes. Here it is necessary to sort through all their combinations both separately and with the tag name.
And there are also data attributes that can also be used in selectors in combination with classes and the tag name.
Well, the most unpleasant, on dynamic pages, what was "unique" can cease to be so at any moment. It is enough, for example, to remove the class that provided uniqueness. By the way, your unique parent
for li will be ul .

P
Pavel Kornilov, 2019-02-04
@KorniloFF

https://codepen.io/KorniloFF/pen/XOgVYz?editors=1011
UPD - corrected the result, now everything seems to be as in the question.
https://codepen.io/KorniloFF/pen/NogBQV?editors=1011

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question