Reputation: 10624
<span class='url_link'>1</span>
<span class='url_link'>2</span>
<span class='url_link'>3</span>
<span class='url_link'>4</span>
<span class='url_link'>5</span>
$(".url_link").each(function(idx, obj){
console.log(this); // <span class="url_link">
console.log(this.text()); // TypeError: this.text is not a function
});
How can I grep the text in span tag?
Upvotes: 0
Views: 579
Reputation: 55750
console.log(this.text())
Should be
console.log($(this).text())
.text()
is a jQuery method
and this is a DOM Object
..
So need to convert that into a jQuery Object before you use .text()
on it..
If you want to use the native javascript then you can try this
console.log(this.innerHTML)
Upvotes: 0
Reputation: 207901
Use console.log($(this).text());
You were trying to use a jQuery function on a non-jQuery object.
Upvotes: 2