$('#main div').not('#2 > #3').each(function() {
$(this).css('background-color', 'blue');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="main">
<div id="1">
<div>Some text in paragraph 1</div>
<div>Some text in paragraph 1</div>
</div><br>
<div id="2">
<div id="3">Some text in paragraph 2</div>
<div>Some text in paragraph 1</div>
</div><br>
<div id="3">
<div>Some text in paragraph 3</div>
<div>Some text in paragraph 1</div>
</div><br>
</div>
I want the css not to be applied for the nested divs of div with id=2. Any suggestions?