I'd like to know if there's an elegant way to accomplish this.
My question: I need to change a few CSS properties of some div elements that have already been created and have those changes be applied to newly created elements of the same class as well.
For example:
CSS:
.myDiv{left:100px}
HTML:
<div id="decode_me">
<div id="div1" class="myDiv">Drink</div>
<div id="div2" class="myDiv">More</div>
</div>
JS:
$('.myDiv').css('left','50px');
$('#decode_me').append('<div id="div3" class="myDiv">Ovaltine</div>');
The first two divs will have left set to 50, while the third will fall back to the css specific 100px. I'm setting left and width based on some window resize events, so it seems creating another class where left is set to 50 wouldn't work as the number will change.
I've looked in to .live and .on and I believe they require some sort of event to trigger them. Short of calling a function to resize everything each time a new element is appended, is there a neat way to do this? My work around seems a bit sledgehammer-ey.
Actual use: Working inside a CMS like framework (phpFox) with jQuery 1.7.1, I've created what is basically a table. It's a bunch of rows that scroll as new rows are added. In each row, I've got 7 "columns", two of which will always be 50px wide. The rest will need to be resized as the "table" is able to be set to full screen without a page load.
If there is another solution, I'd be happy to give it a shot. I started by creating a table, but the amount of styling going on in addition to the scrolling up as new rows are added effect made it a real pain. I've tried using relatively positioned divs, but have run in to trouble with text overflowing. I've now got the "row" set relative, and all of the "column" divs set absolute, but as you can see, that comes with it's own load of problems.
Each solution I come up with like a bit of a mess, I'm thinking there must be a simple way to accomplish this that I'm just missing. PHP guy by trade. Thanks for reading!