stiffle stiffle - 1 month ago 9
Javascript Question

Get value of a Custom Attribute using Javascript or Jquery

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

Like

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


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

Answer

Don't use space in id.

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

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

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

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

Comments