Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert html to javascript [closed]

Does anybody know if there is a tool around that can convert html to javascript.

For example:

<div>
</div>

would convert to

aDiv = document.createElement('div');
document.appendChild(aDiv);

etc

I'm am doing a few html templates for UI components and am using MooShell for prototyping. It would be great to be able to auto-generate the javascript that will build the component's html.

Thanks

like image 992
grookle Avatar asked Aug 19 '10 09:08

grookle


People also ask

Can you convert HTML to JavaScript?

About HTML conversion to JavaScriptThe HTML to JS Converter was created for online converting HTML into JS code. This can come in handy for print HTML code via JavaScript print functions or set into variable, used in most JS frameworks like node. js, react.

Can you turn HTML into an app?

To convert your HTML app to APK, you need to open HTML App Template on AppsGeyser, and insert your code. After that, you need to name the app and upload the icon. It takes up to 5 minutes to build an apk.

How do I code JavaScript in HTML?

You can add JavaScript code in an HTML document by employing the dedicated HTML tag <script> that wraps around JavaScript code. The <script> tag can be placed in the <head> section of your HTML or in the <body> section, depending on when you want the JavaScript to load.


1 Answers

I'd suggest taking a look at John Resig's pure javascript HTML parser. It consists of a SAX style parser for HTML and includes an XML serializer, a DOM builder and a DOM creator. Each takes a string of HTML as input.

In particular, the HTMLtoDOM method could easily be repurposed to return the string of javascript required to build the DOM for any input string of HTML.

like image 177
donalmacanri Avatar answered Oct 12 '22 04:10

donalmacanri