JQuery multiple :not() selector on href not working

253
November 22, 2016, at 1:59 PM

I'm trying to trick a script I found on the web with multiple :not() selectors. Unfortunately I couldn't find why it is not working...

The purpose of the script is to scroll to anchor when clicked. But I have a responsive menu witch contains a anchored link called #menu. So I'm trying to exclude it from the function. Here is my selector:

$(function() {
  $('a[href*=#]:not([href=#]):not([href*='menu'])').click(function() { 
      myfuntion 
  });

Thanks for your help :)

Answer 1

Change the single quotes around menu to double quotes

$('a[href*=#]:not([href=#]):not([href*="menu"])').click(function() { myfuntion });

Inside single quotes 'something here' you can only use double quotes "" to remain in the String context

'something "foo" bar'  

otherwise the parser will expect a string/variable concatenation:

'something'+ foo +'bar' // << correct concatenation with foo variable

or it will throw

'something' foo 'bar'   // << Unexpected identifier / Syntax Error
READ ALSO
cloned item when clicked to , gets back to original form but doesn&#39;t get removed

cloned item when clicked to , gets back to original form but doesn't get removed

I cloned a row of elements. After cloned, the original textbox element is replaced with link.

192
Javascript/jQuery Fail to Append html to body

Javascript/jQuery Fail to Append html to body

I'm working on an android/ios app. i need some sort of infinit scroll, so when user scroll and reaching the end of the page new content will load for him.

271
jQuery position() not working properly in Safari and Opera

jQuery position() not working properly in Safari and Opera

Need help!! I have this on my page and it works perfectly in chrome, firefox and IE. .

276
Slick Slider content wont snap back when resizing browser

Slick Slider content wont snap back when resizing browser

Im using the Slick-Slider as part of a responsive website. the problem is when you resize the browser the content panels in the slider will not swipe and gets stuck.

337