jquery - Can't set element ID in JavaScript, it's always undefined -
i want have function generates id's on fly given jquery object, if doesn't have 1 already. these id's should used in future requests.
i came code below, doesn't work. id's never set. commented out alert statement below return undefined.
i pass code $(this) or $(options.el) parameter substitute 'el'. initially, elements not have explicitly id set in html.
any appreciated, here's code:
getelementid: function(el) { if(undefined == el.attr('id')) { el.attr('id',"anim-"+math.random().tostring().substr(2)); } // alert(el.attr('id')); return el.attr('id'); },
try changing:
if(undefined == el.attr('id'))
to:
if("" == el.attr('id'))
Comments
Post a Comment