简体   繁体   中英

select link with a specific get param

need to select a link which have a specific get param
in the example below the first link should be selected
any help?

 $(document).ready(function(){ let a = 'lorem'; //$('.navb[having c = a]').addClass('act'); });
 .act{ background:orange; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <a class='navb' href='index.php?c=lorem'>abc</a> <a class='navb' href='index.php?c=ipsum'>def</a>

You can try using Attribute Contains Selector like the following way:

 $(document).ready(function(){ let a = 'c=lorem'; $(".navb[href*='"+a+"']").addClass('act'); });
 .act{ background:orange; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <a class='navb' href='index.php?c=lorem'>abc</a> <a class='navb' href='index.php?c=ipsum'>def</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM