Giter Club home page Giter Club logo

node-split's Introduction

node-split

A JavaScript function to find elements that match a query selector, and split their parent elements on either side, reinserting the target element at the top level.

Why

Sometimes an element makes semantic sense nested within other elements (eg. lists), but needs to be displayed at full width. Ideally there would be a CSS float: here; value that would accomplish this. Until there is, this script will break the parent elements apart to approximate it.

How

Put the node-split.js file somewhere.

Use <script src="path/to/node-split.js"></script> to bring it in.

Create a style for elements with the class js-empty-list which sets list-style: none;

In a <script> element, call the nodeSplit() function with a selector list as a string as the only argument, and then call the listCorrector() function, eg:

<ul>
  <li>A list item.</li>
  <li>
    Another list item.
    <p class="split-here">This one has an element that needs to be split out</p>
  </li>
  <li> A third list item.</li>
</ul>

<style>
  .js-empty-list {
    list-style: none;
  }
</style>

<script src="/node-split.js"></script>
<script>
  nodeSplit('.split-here');
  listCorrector();
</script>

See test.html for a more thorough example.

Licence

Released under the MIT Licence.

node-split's People

Contributors

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