ClassList.add.apply throws an TypeError: Illegal invocation exception
Reported by
konr...@gmail.com,
Feb 23 2018
|
|
Issue description
UserAgent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36
Steps to reproduce the problem:
1. Get HTML element from the DOM
2. Invoke `classList.add.apply` on it with several classes in an array.
What is the expected behavior?
This action should add several classes into HTML Element as with `Math.max.apply`.
What went wrong?
TypeError: Illegal invocation exception is thrown.
Did this work before? N/A
Does this work in other browsers? N/A
Chrome version: 64.0.3282.167 Channel: n/a
OS Version: 6.1 (Windows 7, Windows Server 2008 R2)
Flash Version:
Example:
var htmlElem = document.getElementById("elem");
htmlElem.classList.add.apply(null, ["first-class", "second-class"]); /// throws TypeError: Illegal invocation
,
Feb 23 2018
It's not a bug. You need to specify the first argument because add() is not a static method. htmlElem.classList.add.apply(htmlElem.classList, ["first-class", "second-class"]);
,
Feb 23 2018
You should specify classList because "add" is a method of classList.
div.classList.add.apply(div.classList, ...)
If you have more questions, please ask them at other places such as stackoverflow.com.
|
|
►
Sign in to add a comment |
|
Comment 1 Deleted