Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 921
stiffle Avatar asked Sep 01 '12 08:09

stiffle


People also ask

How do I find custom attributes?

Right-click on a user, then click Properties. Click the Attribute Editor tab, then confirm that the custom attribute you created is listed in the "Attribute" column (e.g., LastPassK1).

What is the use of custom attributes?

A custom attribute is a property that you can define to describe assets. Custom attributes extend the meaning of an asset beyond what you can define with the standard attributes. You can create a custom attribute and assign to it a value that is an integer, a range of integers, or a string.

How do I add attributes in JQ?

You can add attributes using attr like so: $('#someid'). attr('name', 'value'); However, for DOM properties like checked , disabled and readonly , the proper way to do this (as of JQuery 1.6) is to use prop .


1 Answers

Don't use space in id.

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

like image 133
jinsky Avatar answered Oct 12 '22 09:10

jinsky