As the title suggests,
I’m looking for an answer to a best practice question,
Is it better to construct DOM elements using JQuery or PHP. backend or frontend.
To give some context,
My PHP loop builds page elements like so;
<div id='content'>
<div id='el1'></div>
<div id='el2'></div>
<div id='el3'></div>
<div id='el4'></div>
</div>
my Jquery script rearranges the DOM like so;
<div id='content'>
<div class='wrapper'>
<div id='el1'></div>
<div id='el2'></div>
</div>
<div class='wrapper'>
<div id='el3'></div>
<div id='el4'></div>
</div>
</div>
The actual task im working on is small, almost as nominal as this example. Would there be any benefit in rewriting the PHP?
thanks,
Cam
If there is no DB or user-input related condition to be met, just do it with PHP. There is no sense changing the DOM with jQuery if it’s known at the outset what the markup should be. You’d be arbitrarily elongating your HTML generation pipeline.