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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -