Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "a[href*=#]:not([href=#])" code mean?

I don't understand clearly what does this code mean ?

a[href*=#]:not([href=#])

Thank you !

like image 614
Tí Pro Avatar asked Sep 06 '25 10:09

Tí Pro


2 Answers

Simply:

a[href*=#] 

gets all anchors (a) that contain # in href.

But with:

:not([href=#])

excludes anchors with href exactly equal to #.

Example:

<a href="#step1">yes</a>
<a href="page.php#step2">yes</a>
<a href="#">no</a> 

the selector gets the first two anchors, but it excludes the last.

For more details you can consult the attribute selectors chapter

like image 55
Luca Rainone Avatar answered Sep 08 '25 01:09

Luca Rainone


Just in case anyone had the same problem as me with it and new version of jQuery : The solution is not to use a[href*=#]:not([href=#]) but

use

a[href*="#"]:not([href="#"])

This was a breaking change in jQuery 2.2.4 onwards.

like image 39
Baldráni Avatar answered Sep 08 '25 03:09

Baldráni