Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
90
rated 0 times [  94] [ 4]  / answers: 1 / hits: 113518  / 12 Years ago, sat, september 1, 2012, 12:00:00

How can I get the value of a custom attribute using JavaScript?


Like


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

I've tried .getAttribute() and jQuery’s .attr() without success.


More From » html

 Answers
15

Adding custom attributes makes your HTML invalid. Use custom data attributes instead:


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

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

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


[#83300] Thursday, August 30, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hailey

Total Points: 355
Total Questions: 91
Total Answers: 91

Location: India
Member since Wed, Aug 4, 2021
3 Years ago
;