Search code examples
javascriptcss-selectorsselectors-api

Use querySelector between slash


Here the point with a exemple :

<h2>        
  <a href="/car/bmw/?load=0&value=5fs4dfsdf45"> </a>
</h2>

I want my querySelector to only select "bmw".

I used it (below), but it's only select the end of the sentence and not the value between "/car/" and "?load"

document.querySelector('h2 > a[href$=]');

Thanks for your help !


Solution

  • try *= instead:

    document.querySelector('h2>a[href*=bmw]')