S
S
sHARek2018-03-23 13:00:47
JavaScript
sHARek, 2018-03-23 13:00:47

How to solve such a "puzzle". Help Me?

Good afternoon.
There is such a code (don't be afraid, this is the code of the guys from Microsoft)
There is a list <ul>with posts / messages.
Each post in its own <li>- there can be a bunch of them

<li id="forum0-Post0-Root" class="ms-comm-postListItem"></li>
- did not begin to spread the code, there is the same as in
<li id="forum0-Post1-Root" class="ms-comm-postListItem">

and in subsequent ones.
How, based on the fact that in <a class="ms-subtleLink" href="#">Александр</a>
textContent == Alexander , set
<li id="тут id всегда меняется" class="ms-comm-postListItem">
- backround = "any color" ?
<li id="forum0-Post0-Root" class="ms-comm-postListItem"></li>
<li id="forum0-Post1-Root" class="ms-comm-postListItem">
<div title="123" class="ms-accessible"></div>
<div class="ms-comm-postMainContainer ms-comm-postSubjectColumn">
<a href="#"><span class="ms-textLarge ms-noWrap">123</span></a>
<div>
  <div class="ms-noWrap ms-comm-postBody">123</div>
</div>
<div class="ms-clear"></div>
<div class="ms-metadata">
<ul class="ms-comm-metalineList ms-noList">
  <li class="ms-comm-metalineItemSeparator ms-comm-metalineItem">
    <span>Автор: <span class="ms-noWrap ms-imnSpan">
      <span class="ms-spimn-presenceLink">
        <span class=" ms-hide">
          <img class="" name="" src="#" alt="">
        </span>
      </span>
      <a class="ms-subtleLink" href="#">О.Е. Виноградова</a>
      </span>
    </span>
  </li>
  <li class="ms-comm-metalineItemSeparator ms-comm-metalineItem">
    <span>Автор последнего ответа: <span class="ms-noWrap ms-imnSpan">
      <a href="#" class="ms-imnlink">
        <img name="" class="ms-hide" src="#" >
      </a>
      <a class="ms-subtleLink" href="#">Александр</a>
      </span>
    </span>
  </li>
    <li class="ms-comm-metalineItem">
      <span>
        <span class="ms-noWrap" title="23.03.2018 11:11">2 мин. назад</span>
      </span>
    </li>
</ul>
  </div>
  </div>
</li>
<li id="forum0-Post2-Root" class="ms-comm-postListItem"></li>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2018-03-23
@sHARek

Array.from(document.querySelectorAll('a.ms-subtleLink'))
  .filter(u => u.textContent === 'Александр')
  .forEach(u => u.style.background = 'red')

you can search not in the entire document, but make a preliminary selection, for example, if it is one on the page. document.querySelector('.ms-comm-metalineList')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question