Niek Oosterbeek Niek Oosterbeek - 2 months ago 7
HTML Question

Select the html in an 'a' tag with jquery but getting html is not a function

Getting:


this.html()
is not a function?


$('a[href*="section"]').click(function() {
var texthtml = this.html();
$(document).find("div.SectionExpandable__title:contains("+texthtml+")").click();
});


How do I get the html from an
a
tag so I can pass it to the next part of the code?

Answer

When using this, you can call DOM methods on it, but not jQuery methods. When using $(this), you can call jQuery methods on it, but not DOM methods.

and html() is jQuery method, so :

Change :

this.html(); 

To :

$(this).html();   
Comments