Giter VIP home page Giter VIP logo

selective-div's Introduction

selective-div

jQuery plugin for having DIV elements bahaving like checkboxes or radio buttons

Getting Started

  1. Download selective-div-plugin-1.0.0.js from dist directory

  2. Add jQuery and selective-div <script> elements to your HTML <head>:

    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script src="selective-div-plugin-1.0.0.js"></script>
  3. Create a couple of div elements you want to behave like radio buttons to your HTML <body>

    <div class="selective-div" data-group="group1" data-value="option1">Option #1</div>
    <div class="selective-div" data-group="group1" data-value="option2">Option #2</div>
    <div class="selective-div" data-group="group1" data-value="option3">Option #3</div>
    Attribute required/optional description
    data-group required Groups multiple elements to behave like radio buttons
    data-value required The selection's value
    class optional You probably want to have your selective elements a look of being touchable
  4. Add selective-div functionality to your div elements by calling $.selectiveDiv() :

    <script type="text/javascript">
    $(document).ready(function(){
    	$('.selective-div').selectiveDiv(); // <- activating selective-div on your DIV elements
    });
    </script>
  5. Add css style to the <head> section to make the selection visible:

    <style type="text/css">
    .selective-div{
    	border:5px solid #999;
    	display:inline-block;
    	cursor:pointer;
    	width:100px;
    	height:100px;
    	margin:5px;
    }
    .selective-div.selected{
    	border: 5px solid #00ff00;
    	display:inline-block;
    }
</style> ```

selective-div adds the class .selected on selected elements.

  1. To access the selected value call $(this).selection('group1'):
  $(".selective-div").click(function(){
      var selectedValue = $(this).selection('group1');
  });
  ```
  
  
  Here's the complete example code:
  ```html
<html lang="en">
  <head>
  <meta charset="UTF-8">
  <title>selectiv-div - example</title>
  <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
  <script src="dist/selective-div-plugin-1.0.0.js"></script>
  <script type="text/javascript">
  
  $(document).ready(function(){
  	$('.selective-div').selectiveDiv(); // <- activating selective-div on your DIV elements
  });
  </script>
  <style type="text/css">
  .selective-div{
  	border:5px solid #999;
  	display:inline-block;
  	cursor:pointer;
  	width:100px;
  	height:100px;
  	margin:5px;
  }
  .selective-div.selected{
  	border: 5px solid #00ff00;
  	display:inline-block;
  }
  </style>
  </head>
  <body>
      <div class="selective-div" data-group="group1" data-value="option1">Option #1</div>
      <div class="selective-div" data-group="group1" data-value="option2">Option #2</div>
      <div class="selective-div" data-group="group1" data-value="option3">Option #3</div>
  </body>
</html>
  ```
  
You can find enhanced examples in the ```demo``` directory

selective-div's People

Contributors

sgerstenlauer avatar

Watchers

 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.