简体   繁体   中英

adding value to title attribute in HTML

Here I am trying to set title dynamically to the native drop-down to show tool-tip, but when I am trying to set title on hover I can't select any value from drop down options. That drop down is getting closed.

$(container).on("hover","select", function (e) {
  $(this).attr("title",$(this).val());
});

What can be the reason for this?

The $.on("hover") event was removed in jQuery 1.9 .

You could try this:

$(container).hover(
  function() {
    $(this).attr("title", $(this).val());
  }, function() {
    $(this).attr("title", "");
  }
);

Try the mouseenter event - not sure whether some other script is closing the dropdown

$('body').on("mouseenter", "select", function (e) {
    $(this).attr("title", this.value);
});

Demo: Fiddle

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