Git Product home page Git Product logo

html-generator's Introduction

html-generator

dynamically generates html from a list of js objects, creating and inserting elements in the DOM


Configuration

Copy the htmlGenerator.js file to your project and insert the tag containing the file path
<script src = "htmlGenerator.js"> </script>


Use of the generator

The HtmlGenerato will be instantiated and in it it is possible to pass two methods, the object with the list of elements listObjectDOM to compose the DOM and the parent element parentElement that contains the element to be inserted.

new HtmlGenerator (listObjectDOM, parentElement)
Example:

new HtmlGenerator ([
                      {   
                          tag: "div",
                          val: "Value",
                          att: {class: "class-name"},
                          childs: [
                              {
                                  tag: "div",
                                  att: {class: "class-name-2.1", id: "id-2.1"},
                                  val: "Value 2.1",
                                  childs: [
                                      {tag: "div", att: {class: "class-name-2-1-1"}, val: "Value 2.1.1"}
                                  ]
                              },
                          ]
                       },
                   ], document.body)
Note: you can only pass the listObjectDOM that the generator will use the body as the parent element.

You can also assign this instance to a variable and insert values ​​and attributes with the methods available on that object.

you can insert attributes to the class using the setAttributes( tag, attributes )

Note: attributes is an object with the values {class: 'class-name', id: 'id-name', ...}

you can enter values for an element using setValue (tag, value)

Note: value is text that the element will contain

List of objects

example:

[
  {
      tag: "tagName",
      val: "value",
      att: {class: "className", id:"idName", style:"", ... },
      childs: [
          {
              tag: "tagName",
              att: {class: "className", id: "idName"},
              val: "value",
              childs: [
                  {tag: "tagName", att: {class: "className"}, val: "value"}
              ]
          },
      ]
  },
  ...
]

html-generator's People

Contributors

atilaassuncao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

html-generator's Issues

enhanced feature

Will the eventlistener function implement in the future?

example:

[
  {
      tag: "tagName",
      val: "value",
      att: {class: "className", id:"idName", style:"", ... },
      event: {load: "funcA", click: "funcB", error: "funcC", ... }
  },
  ...
]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.