Git Product home page Git Product logo

jquery-alterbyobject's Introduction

alterByObject.js

alterByObject.js is a jQuery plugin for modifying your page in a way defined by an object that you can have received from eg. an ajax request.

Usage

Simple

$('.list').alterByObject([{
  selector : '.user',
  addClass : 'new-class'
}]);

That will add the class "new-class" to all elements in ".list" that matches ".user"

Advanced

$('.list').alterByObject([{
  selector : '.user',
  has : 'a[href="http://example.com/profile/foobar"]'
  addClass : 'removed',
  targets : [{
    selector : 'a.unfollow',
    removeClass : 'unfollow',
    addClass : 'follow',
  }]
},
{
  selector : 'h1',
  addClass : 'updated'
}]);

That will add the class "removed" to all elements in ".list" that matches ".user" and that has a child that matches "a[href="http://example.com/profile/foobar"]". It will also change the class "unfollow" to "follow" on the "a.unfollow" element within the ".user" element. In addition to all of that it will add the class 'updated' to all "h1" elements.

Target options

  • selector - a selector for matching the elements that the target want to modify
  • has - a check to make sure that only elements containing the right stuff is modified
  • addClass - a class to add
  • removeClass - a class to remove
  • text - a text to change the elements text to
  • content - HTML content to replace the elements with
  • attr - an object with attributes that should be changed
  • targets - an array of additional targets within this target that should be modified

In action on

  • Flattr.com

jquery-alterbyobject's People

Contributors

voxpelli avatar

Stargazers

Petter Palander avatar  avatar

Watchers

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