search

Home  >  Q&A  >  body text

Look for <a href="<ul>s under <h2> tags that contain a specific URL

I'm working on an export from DocBook to HTML, and there are very few options for the "smart" category of HTML to add.

The structure I get is as follows:

<h2><a href="我用来标识接下来的UL集合的URL">...</a></h2>
<ul>
...
</ul>
There are no categories on

<h2>, nor on <ul>.

So my idea is:

Select the UL after the H2 containing an A with the HREF attribute "My URL".

A combination

h2 ~ ul

is what I originally thought of, but I don't know how to specify H2 with "A of the HREF attributes I want"...

P粉807397973P粉807397973443 days ago579

reply all(1)I'll reply

  • P粉218361972

    P粉2183619722023-09-14 09:32:59

    You can use the has selector to check if h2 has an anchor tag, and then navigate to the next ul selector.

    h2:has(a[href='www.test.com']) + ul {
      color:green;
    }
    <h2><a href="www.test.com">test</a></h2>
    <ul>
    变为绿色
    </ul>
    <h2><a href="www.testing.com">testing</a></h2>
    <ul>
    不变绿色
    </ul>

    reply
    0
  • Cancelreply