element屬性總結

2021-10-03 15:28:15 字數 1754 閱讀 6697

element.classlist本身是唯讀的,但是你可以使用 add() 和 remove()方法修改它。

add( string [, string] )新增指定的類值。如果這些類已經存在於元素的屬性中,那麼它們將被忽略。

remove( string [,string] )刪除指定的類值。

let self = event.target

self.classlist.

add(

'active'

)remove

(class1, class2,

...)

//toggle

(class

,true

|false

)contains

(class

)

$

(this).

removeclass

('u2-l1'

)//刪除class 本身是class 不用加 .$(

this).

addclass

('u2-l1'

)// 增加classif(

$(this).

is('.u2-l1'))

// 是否包含class

elseif(

$(this).

not(

'.u2-l1'))

$("p")

.toggleclass

("main"

)//切換toggle

element.closest(「element」) 方法用來獲取:匹配特定選擇器且離當前元素最近的祖先元素(也可以是當前元素本身)。如果匹配不到,則返回 null

使用方法一樣 $(當前元素).closest(』.祖先元素』)

css選擇器 類選擇器 element.classname 可以拿到element元素中所有class的name

element.classlist是對class的操作

元素選擇器 element.tagname 可以拿到element元素的標籤名 (拿到的為大寫)//html標籤瀏覽器不區分大小寫,一般用小寫

id選擇器 element.id 可以拿到element元素中唯一id

$

('article').

eq(1)

.attr

('id')$

('article').

eq(1)

.prop

('tagname'

)// 此處拿到為大寫$(

'div').

attr

('class'

)//此處拿到class的內容

let a = document.

queryselecot

(element)

a[i] 當element=元素和類時候有效 當為id無效 因為id是唯一的 只有乙個

獲取的是當前元素的所有子節點元素(不包括文字元素),children返回的是htmlcollection型別

document.body.children[1]

.children[0]

element.children.length

extjs中element屬性節點獲取

ext中包含了幾個以get開頭的方法,這些方法可以用來得到文件中dom 得到當前文件中的元件 得到ext元素等,在使用中要注意區別使用。1 get方法 get方法用來得到乙個ext元素,也就是型別為ext.element的物件,ext.element類是ext對dom的封裝,代表dom的元素,可以為...

DOM學習總結 Element型別

element型別用來表現xml和html元素,提供了對元素標籤名 子節點及特性的訪問。訪問標籤名 可以用nodename屬性,也可以用tagname屬性。html中,標籤名始終以大寫表示。xml中標簽名始終與源 中的保持一致。最好在比較之前轉換成相同大小寫形式。id 元素在文件中的唯一標示 tit...

element中一些小問題總結

一 標題el input 新增回車事件 keyup.enter.native二 標題el input同時新增blur和keyup.enter.native會觸發兩次 blur changedata keyup.enter.native event.target.blur 三 el table 在蘋果...