search - find a data attribute just added by jQuery -
search - find a data attribute just added by jQuery -
i adding attributes list-items jquery. later in code trying access these list-items searching attributes added, "undefined not function".
edit:
this bigger part of code can see going on:
var listitems = $('#list li'); area = ''; subarea = ''; (var in areas) { if (areas.hasownproperty(i)) { area = areas[i].area; listitems.find(".area:containsi('" + area + "')").each(function(e) { (var j = areas[i].subareas.length - 1; j >= 0; j--) { subarea = areas[i].subareas[j]; $(this).closest("li").attr("data-area", $(this).closest("li").attr("data-area") + subarea + ' '); } console.log($(this).closest("li").attr("data-area")); }); } } $('#search-input-field').on( { focus: function() { $(this).data('placeholder',$(this).attr('placeholder')); $(this).attr('placeholder',''); }, blur: function() { $(this).attr('placeholder',$(this).data('placeholder')); }, keyup: function() { var searchterm = $(this).val(); var searchsplit = searchterm.replace(/ /g, "'):containsi('"); listitems.attr("data-area").not(":containsi('" + searchsplit + "')").each(function(e) { $(this).addclass('hidden'); });
so searching contained in class within list item, , adding attributes list items data. later search list items containing specific data.
the variable areas used in loop array containing info of areas subaeras, so:
areas = array(id:{area, array(subareas)})
the "containsi" extended version of "contains" works perfectly, not problem.
i noticed info attribute add together doesn't show in source code, leaving me believe jquery saves these attributes in other way. guess why error (since attributes search doesn't exist in doms).
any ideas?
/olof
i think helpful you
here first write .each() function, within function checking attribute nowadays or not.
example code
listitems.find(".area").each(function() { var attr = $(this).attr("attributenamehere"); if (typeof attr !== 'undefined' && attr !== false) { (var j = areas[i].subareas.length - 1; j >= 0; j--) { subarea = areas[i].subareas[j]; $(this).closest("li").attr("data-area", $(this).closest("li").attr("data-area") + subarea + ' '); } console.log($(this).closest("li").attr("data-area")); } });
jquery search attributes undefined
Comments
Post a Comment