Ahoura Ghotbi Ahoura Ghotbi - 1 month ago 5
HTML Question

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.

Answer

This works perfectly:

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

http://jsfiddle.net/mHBuE/