使用 Javascript 或 Jquery 获取自定义属性的值

使用 Javascript 或 Jquery 获取自定义属性的值

问题描述:

如何使用 javascript 或 jquery 获取自定义属性的值?

How can I get the value of a custom attribute using javascript or jquery?

喜欢

<strong id="the id" original-title="I NEED THIS">

我尝试过 .getAttribute() 和 attr()..(Javascrupt & jQuery) 没有成功任何想法?

I've tried with .getAttribute() and attr()..(Javascrupt & jQuery) without success any idea?

不要在 id 中使用空格.

Don't use space in id.

并且添加自定义属性会使您的 html 无效.使用 data-attributes 代替:

And adding custom attributes make your html invalid. Use data-attributes instead:

<strong id="the_id" data-original-title="I NEED THIS">

$('#the_id').data('original-title');

http://jsbin.com/akoyut/2/edit