How to triple nest quotes?

Joined
Mar 25, 2021
Messages
28
Reaction score
0
Hi, how can I triple nest quotes so

JavaScript:
jQuery(".navigation a[href*=#"+rnrSection+"]").parent().addClass("active");

has quotes around the # sign?

I am getting an

Uncaught Error: Syntax error, unrecognized expression: .navigation a[href*=#”+rnrSection+”]

that I think has to do with that.
 
Joined
Nov 13, 2020
Messages
302
Reaction score
38
There is nothing wrong with the statement. If you place spacers in it you would see:


jQuery(".navigation a[href*=#" + rnrSection + "]" ).parent().addClass("active");

You are just inserting rnrSection into the navigation class
 
Joined
Jul 3, 2022
Messages
93
Reaction score
23
HTML:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title></title>
    <script src="https://code.jquery.com/jquery-latest.min.js"></script>
    <style>
    
    </style>
  
  </head>
  <body>   
      <a class="navigation" href="#someSection_1">nav link</a>
    <a class="anotherClass" href="#someSection_2">not nav link</a>
    <a class="navigation" href="#someSection_1">nav link</a>
    <script>
    $(document).ready(function(){
    const rnrSection = 'someSection_1';
    alert( jQuery(".navigation a[href*=#" + rnrSection + "]").length ); // 0 ---> error here
    alert( jQuery("a.navigation[href*=#" + rnrSection + "]").length ); // 2 no any error
    });
    </script>
  </body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top