GithubHelp home page GithubHelp logo

freedom's Introduction

FreeDOM

FreeDOM is a JavaScript Document Object Model (DOM) Manipulation Library that simplifies accessing properties of DOM elements on a page for users.

How to use FreeDOM:

  1. Download the lib folder
  2. Be sure to include the script tag referring to the freedom.js file in the head of your HTML file. If you are using webpack, make sure that you put this tag above the bundle.js one! For example: ```html <script src="path/to/freedom.js"></script> <script src="./js/bundle.js"></script>
```

FreeDOM offers a variety of methods that the user can use in the browser console in order to inspect elements. For example, users can:

  • add classes to a group of DOM elements using the addClass method.

    before:

    <div> no class </div>
    <div> classless </div>
    <div> give me a class! </div>
    div = $j('div');
    div.addClass('green-background');

    after:

    <div class="green-background"> yay! </div>
    <div class="green-background"> i'm green </div>
    <div class="green-background"> in my background! </div>

    How did this work?

    addClass (newClass) {
        this.nodes.forEach((el) => {
          el.classList.add(newClass);
        });
    }
  • remove all elements of a single type from a page

    before:

    <div> goodbye div! </div>
    <div> extra div! </div>
    <div> unnecessary div! </div>
    <p> finally something worth keeping </p>
    <div> go away div! </div>
    div = $j('div');
    div.remove();

    after:

    <p> finally something worth keeping </p>
  • perform different actions using FreeDOM's versatile $j function

    $j responds to different inputs that you give it

    window.$j = (selector) => {
      if (selector instanceof Function) {
        if (!ready){ // putting in a function will add it to a queue of actions to perform
          queue.push(selector);
        } else {
          selector();
        }
      }
      else if (selector instanceof HTMLElement) {
        return new DOMNodeCollection([selector]);
      }
    	else if (selector === window) {
    		return new DOMNodeCollection([window]);
    	}
      else {
        let selected = document.querySelectorAll(selector);
        let arraySelected = Array.from(selected);
         // giving a string as an input will return a collection of all elements of that type
        return new DOMNodeCollection(arraySelected); // $j('li') returns a collection of all <li> items on the page.
        }
    };

freedom's People

Contributors

jeffreydu avatar

Stargazers

Sam Cross avatar Dzheni Dilcheva avatar Anthony John Deluca avatar

Watchers

James Cloos avatar  avatar

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.