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
Post a Comment