get class name from element with onclick

后端 未结 7 1925
我在风中等你
我在风中等你 2020-12-10 08:01

Because of different reasons I can NOT use $(\'.class\').click or on(\'click\', function..)

So I really have to use the onclick=\"\" event from the html element.

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-10 08:21

    From jsfiddle you provided, edit your code like below and you'll get answer (class) properly.

    CLICK HERE
    
    function someFunction(obj,abc) {
        alert(abc);
        alert(obj.getAttribute('class'));   
    }
    

    Pass this as first argument and then access it in function with obj. After that you can use obj.getAttribute('class')

提交回复
热议问题