javascript - Access inner text using $(this) with jQuery -


i have button , want log inner text using jquery when button clicked. know how use id text of buttton ($("#testid").text()), that's not option me. use $(this) keyword instead of id, i'm not sure how that.

the html:

<button id="testid" onclick="getbuttontext()">button text</button> 

the javascript:

function getbuttontext() {     console.log("this text = " + $(this).text()); //not working } 

pass in this

the html:

<button id="testid" onclick="getbuttontext(this)">button text</button> 

the javascript:

function getbuttontext(self) {     console.log("this text = " + $(self).text()); //not working } 

otherwise, this window object


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -