Giter Club home page Giter Club logo

showhide.js's Introduction


showhide.js

Showhide.js is a small and extremely simple, dependency-free library to show and hide elements conditionally based on HTML data attributes. It is quite useful to create simple interactions on pages without much hassle, which is ideal for prototyping.

Getting started

1. Installing

Clone showhide.js repository to a folder of your choice in your web project, e.g. /var/www/project/js:

cd /var/www/project/js && git clone https://github.com/Dovyski/showhide.git showhide

2. Include showhide.js in your HTML file

Just before the </head> or </body> tags, add the following:

<script src="js/showhide/showhide.js"></script>

Usage

Showhide.js uses HTML data attributes to control the show/hide logic. All happens when the user clicks an HTML element that has a data-sh-show or data-sh-hide data element:

<a href="javascript:void(0);" data-sh-show=".dynamic">Show</a>
<a href="javascript:void(0);" data-sh-hide=".dynamic">Hide</a>

<div class="dynamic">This div will be visible (or not)</div>

When the user clicks any of the <a> tags above, if it has an data-sh-show data attribute, Showhide.js will search for all elements in the page that match the query informed as the value for the data attribute, then make them visible. Similarly, if the user clicks an element with a data-sh-hide attribute, Showhide.js will hide all elements that match that query.

Showhide.js also has built-in support to create toggle-based controls:

<a href="javascript:void(0);" data-sh-toggle=".dynamic.red" data-sh-toggle-show=".toggle-show-red" data-sh-toggle-hide=".toggle-hide-red">
          
  <span class="toggle-show-red" style="display: none;">[on]</span>
  <span class="toggle-hide-red">[off]</span>
</a>

The query informed in data-sh-show, data-sh-hide, or any other data attributes supported by Showhide.js is based on jQuery selectors. It means you can do something like data-sh-show="#elementId" to show an element by its id.

Limitations

Showhide.js was developed to quickly (and dirtly) show or hide elements on a page based on simple rules. It's biggest advantages are that is has no dependencies, e.g. jQuery, and is extremely simple to use. If you are looking for something more robust or powerful, check Vue.js or React.

License

Showhide.js is licensed under the terms of the MIT Open Source license and is available for free.

Changelog

See all changes in the CHANGELOG file.

showhide.js's People

Contributors

dovyski avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

showhide.js's Issues

Add a proper README

The current README is a placeholder. A more informative one is beyond required. If you are interested in this project, be a bit patient.

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.