Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert static HTML page to dynamically generated jQuery

I have an odd requirement where we have static html/css/images. I then need to convert these static pages into pages that are dynamically generated with javascript/jquery. We are dealing with 100+ instances of this.

So for example:

<div id='foo' title='my title'>Hi there!</div>

would be converted to:

$('<div/>', {
    id: 'foo',
    title: 'my title',
    text: 'Hi there!'
}).appendTo('#mySelector');

Is there a way to do this programmatically? I googled around but was not able to find anything.

like image 651
Alexis Avatar asked Jun 27 '26 18:06

Alexis


1 Answers

Something like this?

<div></div>

$('div').append('<p></p>');
$('div p').attr({
    'id':'foo',
    'title':'my title'
}).text('Hi there!');

OUTPUT :

<div><p id="foo" title="my title">Hi there!</p></div>
like image 98
Anthony Carbon Avatar answered Jun 29 '26 08:06

Anthony Carbon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!