beginner beginner - 3 months ago 8
jQuery Question

Is there any way to select every element except one in .on() function

I am adding a function to all the future created elements of

<div id="content">


<div id="content">
<h3 id="title">tiltle</h3>
</div>
<script>
$("#content").on("click","*",function(){($(this).hide();});
</script>


this works fine, but i don't want to bind this function to
<h3 id="title">
I tried

<div id="content">
<h3 id="title">tiltle</h3>
</div>
<script>
$("#content").on("click","*.not('#title')",function(){($(this).hide();});
</script>


But this is not working , can anyone help me to find efficient solution?

Answer

Use :not() pseudo-class selector

$("#content").on("click",":not(#title)",function(){ 
    $(this).hide();
});