Get ID of element that fired the Jquery function
I have a repeater, and each row will show a tool tip, each tool tip will include the row ID , this is my code :
$(document).ready(function () {
$('tr.SomeClass').开发者_开发百科qtip({
content: {
text: // here I want to get the id of the row
},
You need to use a .each()
to loop through the elements here, like this:
$(document).ready(function () {
$('tr.SomeClass').each(function() {
$(this).qtip({
content: {
text: "My ID is: " + this.id
}
});
});
});
With this approach, this
refers to each tr.SomeClass
element as you go, rather than whatever context you're in (previously document
, since you were in a document.ready
handler).
精彩评论