Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery get a custom (made up) Attribute value

I have a the following html piece :

<div onClick="javascript:getComments(this);" store-id="143568" class="CountryRow" style="padding: 4px;"><div class="flag flag_az"></div> &nbsp; Azerbaijan</div>

and I would like to create a jquery function to get the value of store-id. I have the following however its not working :

 getComments = function(input) {
   fValue = $(input).val( $(input).attr("store-id") );
   alert('the ID :'+fValue);
 }

can someone be kind enough to tell me what it is that I am doing wrong.

like image 571
Ahoura Ghotbi Avatar asked Dec 07 '22 18:12

Ahoura Ghotbi


1 Answers

This works perfectly:

getComments = function(input) {
  fValue =  $(input).attr("store-id");
  alert('the ID :'+fValue);
}

http://jsfiddle.net/mHBuE/

like image 195
samura Avatar answered Dec 10 '22 13:12

samura