What is the difference between class and classname in javascript?

前端 未结 3 1526
面向向阳花
面向向阳花 2020-12-15 07:31

In order to find children objects of a certain class name, I had to create my own helper function

findChildrenByTagName = function(obj, name){
    var ret =          


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-15 07:57

    Don't get confused between the reserved word 'class' and 'className' attribute of DOM element.

    According to MDN:

    The name className is used for this property instead of class because of conflicts with the "class" keyword in many languages which are used to manipulate the DOM.

    EDIT: The 'class' word used on js 1.0 but in js 2.0 was merged with ECMAScript 4 which was rather unpopular and depreciated. but it is still a reserved word.

提交回复
热议问题