Git Product home page Git Product logo

mydom's Introduction

一 创建元素

//create的用法
dom.create(`<div>text</div>`);
// after和before的用法
const afterSibling=dom.create(`<li>弟弟</li>`);
const beforeSibling=dom.create(`<li>哥哥</li>`);
const test=document.querySelector('.test');
dom.after(afterSibling,test);
dom.before(beforeSibling,test);
// append的用法
const container=document.querySelector('.container');
const littlered=dom.create(`<li>小红</li>`);
dom.append(container,littlered);
// wrap的用法
const div2=document.querySelector('.div2');
const div3=dom.create(`<div>text</div>`);
dom.wrap(div2,div3);

二 删除元素

// remove的用法
dom.remove(littlered);
// empty的用法
dom.empty(container);

三 修改元素

// attr的用法
const div1=document.querySelector('.div1');
//写
dom.attr(div1,'title','red');
//读
dom.attr(div1,'title');
// text的用法
//写
dom.text(div1,'hi i am beauty');
//读
dom.text(div1);
// html的用法
//写
dom.html(div1,'<div>hi</div>');
//读
dom.html(div1);
// style的用法
dom.style(container,{color:'pink',border:'1px solid blue'});
dom.style(container,'color');
dom.style(container,'background','orange');
// class.add的用法
dom.class.add(container,'class1');
// class.has的用法
dom.class.contains(container,'class1');
// class.remove的用法
dom.class.remove(container,'class1');
// class.has的用法
dom.class.contains(container,'class1');
// on的用法
const fn=()=>{alert("你真美")}
dom.on(container,'click',fn);
// off的用法
dom.off(container,'click',fn);

四 查找元素

// find的用法
dom.find('ul li');
dom.find('#test');
dom.find('.test');
dom.find('.test');
// findAll的用法
dom.findAll('.hong li');
// parent的用法
dom.parent(name);
// children的用法
dom.children(dom.find('ul'));
// siblings的用法
dom.siblings(name);
// next的用法
dom.next('.lan');
// previous的用法
dom.previous(dom.find('.lan'));
// each的用法
dom.each(dom.children(dom.find('.hong')),(n)=>{dom.style(n,{color:'red'})});
// index的用法
console.log(dom.index(name));

mydom's People

Contributors

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