javascript - Object [object HTMLAnchorElement] has no method 'attr' -
i'm examining dom element using console.log. dom element anchor:
<a href="#" class="videoimage" data-id="ks3h_s3e-wc"></a>
when try access id , output using either of following lines:
console.log($this.attr(data-id));
or
console.log($this.data('id'));
i error:
object [object htmlanchorelement] has no method 'attr'
('data' in second case)
does anchor element not have attr or data methods, or mistake else?
that looks because this
reference not jquery
object. try these instead:
$(this).data('id') $(this).attr('data-id')
Comments
Post a Comment