Loading...

javascript change css class

Temperature: 0 °C

Mark ChangMark Chang
author_tools


javascript change css class
使用classList是一個方便的替代方法,可以將元素的類列表作為空格分隔的字符串來訪問。

document.getElementById("MyElement").classList.add('MyClass');
document.getElementById("MyElement").classList.remove('MyClass');
if ( document.getElementById("MyElement").classList.contains('MyClass') )
document.getElementById("MyElement").classList.toggle('MyClass');

不幸的是,這些在Internet Explorer v10之前的版本中不起作用。

但我想這些應該都是已經是不變的事實~所以也不意外了。

Internet Explorer 永遠都是工程師的惡夢( ̄∇ ̄)

https://innstory.com/story-javascript_change_css_class-1842
javascript

Prev
 fancybox_close的方式

Next
嘰嘰喳喳 

About the Author

Mark Chang

離不開電腦的宅男

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

刪除已上傳至server的檔案

刪除已上傳至server的檔...

a5 管理系統,難免都會遇到要更新或刪除已經上傳到server的檔案。 總不能只是重新上傳卻又不把舊...

文件上傳過程中使用白名單、黑名單、或者MIME做認證

文件上傳過程中使用白名單、黑...

pexelsphotolock5 是不是被資安的問題搞得很煩? 我想,在建置系統的過程中,或多或少都...

使用CSS 讓ul li 橫向水平

使用CSS 讓ul li 橫...

好吧,其實這個css常在用,但我每次都沒特別紀錄,然後每次又忘記然後又要Google。 其實主要就是...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format