This may be a stupid question, maybe I have been up too long, but is there any way to add a class to an element and have it affect the elements children only?
$('#add').click(function(){ $('.parent').append("<div class='child'></div>"); }); $('#bg').click(function(){ $('.child').css('background-color', 'orange'); }); .parent { background-color:yellow; border: 2px solid black; height:200px; width: 300px; } .child { height:15px; width:280px; border: 1px solid black; margin-top:10px; margin-bottom:10px; margin-left:5px; background-color:white; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class='parent'> <button id='add'>Add another</button><button id='bg'>Change Background</button> <div class='child'></div> <div class='child'></div> <div class='child'></div> </div> Refer to snippet, I need the parent div background color to remain white, but I need to change the css so it affects all future dynamically created div's.