Cross-browser, javascript getAttribute() method?

前端 未结 3 1734
無奈伤痛
無奈伤痛 2020-12-14 03:45

trying to determine a decent, cross browser method for obtaining attributes with javascript? assume javascript library use (jQuery/Mootools/etc.) is not an option.

I

3条回答
  •  没有蜡笔的小新
    2020-12-14 04:41

    For the vast majority of cases you can simply use the built in getAttribute function.

    e.g.

    ele.getAttribute(attr)
    

    According to QuirksMode this should work on all major browsers (IE >= 6 included), with a minor exception:

    In IE5-7, accessing the style attribute gives an object, and accessing the onclick attribute gives an anonymous function wrapped around the actual content.

提交回复
热议问题