I’m currently facing this problem where :not(this)
is not working but is working when I specify the exact element selector. Please see my code sample below.
JavaScript
x
7
1
$(document).ready(function(){
2
$('p').on('click', function(){
3
4
$('p:not(this, .intro)').css('background', 'yellow');
5
6
});
7
});
JavaScript
1
6
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
2
3
4
<p class="intro">My name is Donald.</p>
5
<p>I live in Duckburg.</p>
6
<p>My best friend is Mickey.</p>
Advertisement
Answer
JavaScript
1
5
1
$(document).ready(function(){
2
$('p').on('click', function(){
3
$('p:not(.intro)').not(this).css('background', 'yellow');
4
});
5
});
JavaScript
1
6
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
2
3
4
<p class="intro">My name is Donald.</p>
5
<p>I live in Duckburg.</p>
6
<p>My best friend is Mickey.</p>