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
Post a Comment