Code Monkey home page Code Monkey logo

jquery-helpers's Introduction

jQuery Helpers

A set of jQuery Helpers for front-end development.

Quick start

Place the following <script>s near the end of your pages, right before the closing </body> tag, to enable them. jQuery must come first, and then our plugins.

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/jquery.helpers.js"></script>

Download

You can download ready-to-use compiled code to easily drop into your project: Download jQuery Helpers.

Usage

jQuery('.element').exists()

This code lets you check whether an element exists or not.

if ($('.element').exists()) {
  var length = $('.element').exists();
  console.log('There are ' + length + ' elements in the page.');
}
$('.element').exists(function(length) {
  console.log({
    length: length,
    content: $(this).html(), 
  });
}, function () {
  console.log('There are no selected elements in the pages.');
});
$('.element').exists(function(length) {
  console.log({
    length: length,
    content: $(this).html(), 
  });
});
$('.element').exists(null, function() {
  console.log('There are no selected elements in the pages.');
});

jQuery(window).matchMedia()

This code lets you handle things differently when the window is very narrow.

var isMobile = $(window).matchMedia('(max-width: 767px)');

if (isMobile) {
  console.log('Mobile');
} else {
  console.log('Desktop');
}
$(window).matchMedia('(max-width: 767px)', function (matches) {
  if (matches) {
    console.log('Mobile');
  } else {
    console.log('Desktop');
  }
});
$(window).matchMedia('(max-width: 767px)', function () {
  console.log('Mobile');
}, function () {
  console.log('Desktop');
});

jquery-helpers's People

Contributors

viendinhcom avatar

Watchers

James Cloos avatar  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.