Skip to content
On this page

super-tools-lib - v1.74.0 / Modules / class / Dom

Class: Dom

class.Dom

Dom 类

Since

1.62.0

Example

ts
import { Dom, $ } from 'super-tools-lib'

const dom = new Dom('selector')

dom.setCss({color: 'red'})

// 或者使用已经封装好的 $方法

$('selector').setCss({color: 'red'})

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Dom(selector)

构造函数

Parameters

NameTypeDescription
selectorstring选择器

Properties

_element

Private _element: HTMLElement

Dom 类的私有属性

Methods

addClass

addClass(className): Dom

添加类名

Parameters

NameTypeDescription
classNamestring要添加的类名

Returns

Dom

返回 Dom 实例


first

first(): ChildNode

获取同级别第一个元素

Returns

ChildNode


getDom

getDom(): HTMLElement

获取dom 节点

Returns

HTMLElement

返回 dom 节点


getHtml

getHtml(): string

获取子级html 方法

Returns

string


getVal

getVal(): string

获取表单元素的值

Returns

string


insertHtmlAfter

insertHtmlAfter(html): Dom

在元素后插入给定的HTML

Parameters

NameTypeDescription
htmlstringhtml 字符串

Returns

Dom

返回 Dom 实例


insertHtmlBefore

insertHtmlBefore(html): Dom

在元素前插入给定的HTML

Parameters

NameTypeDescription
htmlstringhtml 字符串

Returns

Dom

返回 Dom 实例


last

last(): ChildNode

获取同级别最后一个元素

Returns

ChildNode


next

next(): ChildNode

获取下一个同级别元素

Returns

ChildNode


on

on(eventType, callback): Dom

on 方法

Parameters

NameTypeDescription
eventTypestring事件类型
callback() => void回调函数

Returns

Dom

返回 Dom 实例


prev

prev(): ChildNode

获取上一个同级别元素

Returns

ChildNode


removeClass

removeClass(className): Dom

移除类名

Parameters

NameTypeDescription
classNamestring要移除的类名

Returns

Dom

返回 Dom 实例


setCss

setCss(styles): Dom

设置css 方法

Parameters

NameTypeDescription
stylesobject样式对象

Returns

Dom

返回 Dom 实例


setHtml

setHtml(html): Dom

设置html 方法

Parameters

NameTypeDescription
htmlstringhtml 字符串

Returns

Dom

返回 Dom 实例


setVal

setVal(value): Dom

设置表单元素的值

Parameters

NameType
valuestring

Returns

Dom