简体   繁体   中英

Bootstrap Tooltip - How can I access “this”

I have created a function to show bootstrap tooltips based on the id of the link the user is hovering over.

Alerting this.id is blank inside the title function - do I need to pass this through and if so how? (this) doesn't work and I've tried a few other methods to no avail. Thank you!

$(document).ready(function(){
  $('.tooltiplink').tooltip({ 
    html: true,
    title: function() {
      return $('#' + this.id).html();
    }
  });
});

Use $(this) . There is no need for using $('#' + this.id) . $(this) is already the element you're looking for.

$(document).ready(function(){
  $('.tooltiplink').tooltip({ 
    html: true,
    title: function() {
      return $(this).html();
    }
  });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM