Code Monkey home page Code Monkey logo

jquery-morphdom's Introduction

jquery-morphdom

A jQuery wrapper for morphdom - a fast and lightweight DOM diffing/patching (without the virtual part)

About Morphdom

Lightweight module for morphing an existing DOM node tree to match a target DOM node tree. It's fast and works with the real DOM no virtual-DOM here!

If you need more information, check the morphdom repo.

Usage

This library can be used to instead of .html or .replaceWith, but keep in mind that this replaces the item itself, not just the inside contents. So it is much more like .replaceWith.

// this is how .html works
$('#somediv').html("<div id=\"newdiv\">I will be inside #somediv</div>");

// this is how .replaceWith and .morphdom work
$('#somediv').replaceWith("<div id=\"newdiv\">I will replace #somediv</div>");
$('#somediv').morphdom("<div id=\"newdiv\">I will replace #somediv</div>");

Example

See the example.html for the full use case.

jQuery(document).ready(function ($) {
    // replace #div with #newid
    $('#div').morphdom("<div id=\"newid\">New Text</div>");

    // replace the first li with the last one
    $('ul').find('li').first().morphdom($('ul').find('li').last());

    // replaces #fetched with the contents of partial.html
    $.get('partial.html', function (data, textStatus, jqXHR) {
        $('#fetched').find('.item').morphdom(data);
    });
});

Usage With Require

Please see this requirebin project.

Use Cases

  • loading form data via AJAX
  • partial content, replacing other content
  • AJAX pagination
  • timeout changes to HTML
  • updates to DOM for input events
  • sortable display of elements

jquery-morphdom's People

Contributors

james2doyle avatar

Watchers

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.