admin管理员组

文章数量:1431955

Good day,

I have received the following error:

Uncaught Error: Syntax error, unrecognized expression: a[href*=#]:not([href=#]) for the library jquery-2.2.3.min.js:2

Below is the code:

$(document).ready(function() {
    $('.collapse').on('show.bs.collapse', function() {
        var id = $(this).attr('id');
        $('a[href="#' + id + '"]').closest('.panel-heading').addClass('active-faq');
        $('a[href="#' + id + '"] .panel-title span').html('<i class="glyphicon glyphicon-minus"></i>');
    });
    $('.collapse').on('hide.bs.collapse', function() {
        var id = $(this).attr('id');
        $('a[href="#' + id + '"]').closest('.panel-heading').removeClass('active-faq');
        $('a[href="#' + id + '"] .panel-title span').html('<i class="glyphicon glyphicon-plus"></i>');
    });
});

I am using the latest Jquery CDN

<!-- Javascript and Jquery files -->
<script   src=".2.3.min.js"   integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo="   crossorigin="anonymous"></script>

Good day,

I have received the following error:

Uncaught Error: Syntax error, unrecognized expression: a[href*=#]:not([href=#]) for the library jquery-2.2.3.min.js:2

Below is the code:

$(document).ready(function() {
    $('.collapse').on('show.bs.collapse', function() {
        var id = $(this).attr('id');
        $('a[href="#' + id + '"]').closest('.panel-heading').addClass('active-faq');
        $('a[href="#' + id + '"] .panel-title span').html('<i class="glyphicon glyphicon-minus"></i>');
    });
    $('.collapse').on('hide.bs.collapse', function() {
        var id = $(this).attr('id');
        $('a[href="#' + id + '"]').closest('.panel-heading').removeClass('active-faq');
        $('a[href="#' + id + '"] .panel-title span').html('<i class="glyphicon glyphicon-plus"></i>');
    });
});

I am using the latest Jquery CDN

<!-- Javascript and Jquery files -->
<script   src="https://code.jquery./jquery-2.2.3.min.js"   integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo="   crossorigin="anonymous"></script>
Share Improve this question asked May 4, 2016 at 16:50 user5453902user5453902 1
  • None of the code you've shown produces that selector? – Bergi Commented May 4, 2016 at 17:04
Add a ment  | 

2 Answers 2

Reset to default 4

The # is a special character and needs to be escaped like:

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

Source: https://github./jquery/jquery/issues/2885

If I understand what you are trying to do you seem to have an extra # in your selector.

See this jsfiddle for a working example

本文标签: javascriptUncaught Error Syntax errorunrecognized expression ahref*not(href)Stack Overflow