jquery - Using the data-* on input element -


so have discovered data-* attribute , have been using ajax set the id's on link element destination.

ex;

<a id="link_id" href="url_for_no_ajax" class="some_class" data-container="#main">display text</a> 

so way can create php function make link non-java users , use id attribute , data-container attribute ajax.

it working fine.

i wanted same inputs element reason not working. data-* attribute not showing in source of page.

so must assume cant use data-* attribute input's

so question element can take data-* attribute? or if faster answer witch can't take it?

tank stackoverflow community! (=

edit

the line output input php :

echo '<input id="'.$id.'" type="'.$type.'" name="'.$name.'" size="'.$size.'" class="'.$class.'" value="'.$value.'"><br><br>'; 

then how retrieve value of data attribute jquery ajax :

var data_type = ($(this).attr("data-type")); 

if alert(data_type) telling me undefined.

inputs can take data element. here test case:

jsfiddle demo

html:

<a href="#" data-container="a-tag">click me</a><br><br> <input type="text" data-container="an_input" /><br><br> <div data-container="a_div">div here</div> 

js:

$('*').click(function(){     var d = $(this).data();   alert(d.container);   return false; }); 

references:

http://ejohn.org/blog/html-5-data-attributes/

http://api.jquery.com/data/

the .data() method allows attach data of type to dom elements in way safe circular references , therefore memory leaks.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -