A minimalist DOM manipulation library with TypeScript support.
npm install kinwin
Note: Package will be available on npm soon. For now, you can install directly from GitHub:
npm install github:aliirz/kinwin.js
import { kw, Http } from 'kinwin';
// DOM Manipulation
const element = kw('#myId')
.addClass('active')
.attr('title', 'Active Element')
.html('New Content');
// Event Handling
kw('.button').on('click', (e: Event) => {
console.log('Clicked!', e.target);
});
// Form Handling
const form = kw('#myForm');
form.on('submit', async (e: Event) => {
e.preventDefault();
const data = form.serialize();
// HTTP Requests
try {
const response = await Http.post('/api/submit', data);
console.log('Success:', response);
} catch (error) {
console.error('Error:', error);
}
});
// Animations
await kw('.modal')
.fadeIn(300)
.addClass('visible');
// Event Delegation
kw('#list').delegate('click', '.item', (e: Event) => {
kw(e.target as Element).toggleClass('selected');
});
// DOM Manipulation
const element = kw('#myId')
.addClass('active')
.attr('title', 'Active Element')
.html('New Content');
// Event Handling
kw('.button').on('click', (e) => {
console.log('Clicked!', e.target);
});
// Form Handling
const form = kw('#myForm');
form.on('submit', async (e) => {
e.preventDefault();
const data = form.serialize();
// HTTP Requests
try {
const response = await Http.post('/api/submit', data);
console.log('Success:', response);
} catch (error) {
console.error('Error:', error);
}
});
// Animations
kw('.modal')
.fadeIn(300)
.addClass('visible')
.then(() => console.log('Animation complete'));
// Event Delegation
kw('#list').delegate('click', '.item', (e) => {
kw(e.target).toggleClass('selected');
});
KinWin supports multiple selector types:
- ID:
kw('#id-attribute')
- select by ID - Class:
kw('.class-attribute')
- select by class - Name:
kw('@name-attribute')
- select by name attribute - Tag:
kw('=tagname')
- select by tag name
html()
- Get/set HTML contentattr()
- Get/set attributesval()
- Get/set form valuesshow()
- Show elementshide()
- Hide elementsappend()
- Append contentprepend()
- Prepend contentremove()
- Remove elements
addClass()
- Add classesremoveClass()
- Remove classestoggleClass()
- Toggle classeshasClass()
- Check class existence
on()
- Add event listenerdelegate()
- Event delegationoff()
- Remove event listener
serialize()
- Serialize form dataval()
- Get/set form values
Http.get()
- GET requestHttp.post()
- POST requestHttp.put()
- PUT requestHttp.delete()
- DELETE request
fadeIn()
- Fade infadeOut()
- Fade outslideIn()
- Slide in
KinWin supports all modern browsers (Chrome, Firefox, Safari, Edge).
MIT