Giter Site home page Giter Site logo

kpion / yes Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 23 KB

Experimental javascript querySelector/querySelectorAll wrapper, based on native Proxy object, and Array. Enables DOM manipulation with native DOM API.

HTML 32.63% JavaScript 67.37%
nodelist dom dom-manipulation

yes's Introduction

"Yes" : Introduction

"Yes" - Javascript (experimental) wrapper around querySelector and querySelectorAll with the Proxy object and extending the Array class. 3KB minified.

"Yes" comes from a misspelled "Yet Another Selector" :)

I.e. the jQuery-like library (limited to selecting and manipulating elements though), based on native DOM API.

This is alpha stage.

Instead of doing (in vanilla javascript):

    document.querySelectorAll('.some-class').forEach(elem => {
        elem.setAttribute ('title', 'new title');
    });   

You can do:

    y('.some-class').setAttribute ('title', 'new title');

This works because the "y" object above will simply call setAttribute on all the matching elements. Same with properties, instead of :

    document.querySelectorAll('.some-class').forEach(elem => {
        elem.style.color = '#999';
    });  

You can do:

    y('.some-class').style.color = '#999';

This is done thanks to the Proxy Object - we just 'trap' the calls/property access and pass it to the list of matching nodes.

And, thanks to the fact that "Yes" extends (inherits from) the Array class, we can do something like:

    //only divs:
    let filtered = y(y('.some-class').filter(elem => elem.tagName === 'DIV'));
    filtered.style.border = '10px solid #aad';

And of course forEach:

    y('.some-class').forEach(elem => {
        elem.style.textShadow ='-2px -2px 2px #bbb';
    });

See 'index.html' file.

To be continued.

yes's People

Contributors

kpion avatar

Watchers

 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.