jQuery: How to add the attribute in $(this)? -


example have 10 textbox , each has same attribute different value, example have attribute data-same different value , have in code
$('#test').each(function(){ $(this).val(); });
and want filter result using attribute of each textbox. how it? thinking on doing this
$('#test').each(function(){ $('[data-same="val1"]',this).val(); });
but i'm not sure it.

use attr()

$('#test').each(function(){      var attributevalue = $(this).attr('data-same');      //do whatever want value }); 

also, code indicates have same id multiple elements. avoid , use classes or attributes instead.

$('[data-same]').each(function(){          var attributevalue = $(this).attr('data-same');          //do whatever want value     }); 

see why bad thing have multiple html elements same id attribute?


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -