Why is jslint producing an error here?

时间:2017-04-10 00:13:25

标签: javascript

Regarding the code snippet below:

if (type === '#') {
    return doc.getElementById(identifier);
} else if (type === '.' && doc.getElementsByClassName) {
    return doc.getElementsByClassName(identifier);
} else if (type === '@') {
    return doc.getElementsByName(identifier);
}

enter image description here

It appears not to lik the if / else if all together?

2 个答案:

答案 0 :(得分:0)

You have a return in your if block, so any else and else if blocks following it are unnecessary since they would never be evaluated if the function returned.
Try change the else ifs to just ifs.

答案 1 :(得分:0)

I think that in the else if (type === '.' && doc.getElementsByClassName) { is missing the class in doc.getElementsByClassName

You should add the class name, i.e.:

doc.getElementsByClassName('className');