Git Product home page Git Product logo

mutate-dom's Introduction

mutate-dom

DOM mutator for A/B experiments.

Dependency Status Build Status npm version

Installation

npm i --save mutate-dom

Usage example

The HTML to mutate.

<div class="user">
  <div class="name">John</div>
  <div class="ava-container">
    <img src="http://api.randomuser.me/portraits/thumb/men/39.jpg"/>
  </div>
</div>

The code that mutates the HTML.

var mu = require('mutate-dom');
var mutator = require('mutate-dom').mutator;

mu.addClass = mutator(function(el, newClass) {
  $(el).addClass(newClass);
});

mu.src = mutator(function(el, src) {
  $(el).attr('src', src);
});

mu({
  '.user': {
    '.name': 'Bill',
    '.hobbies': mu.slice(0, 1, 'football'),
    '.ava-container': [{
        img: mu.src('http://api.randomuser.me/portraits/thumb/men/59.jpg')
      },
      mu.addClass('awesome-ava-container')
    ]
  }
});

License

MIT © Zoltan Kochan

mutate-dom's People

Contributors

zkochan avatar

Watchers

 avatar  avatar

mutate-dom's Issues

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.