get class name from element with onclick

后端 未结 7 1918
我在风中等你
我在风中等你 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:40

    you need to pass this reference when calling the function

    try this

    CLICK HERE
    ......  //same for others
    

    jquery

    function someFunction(obj,abc) {
            alert(abc);
            alert($(obj).attr('class'));
    
        }
    

    with plain javascript (without Jquery)

    function someFunction(obj,abc) {
            alert(obj.className);
    }
    

    fiddle here

提交回复
热议问题