Jquery - get html attribute from function call

I am trying to call another hint according to the id attribute of the anchor tag. My JavaScript code is as follows:

$(function()
{
   $('.tippy').qtip(
   {
      content: {
          url: "http://mydomain.com/product/mini/" + $(this).attr("id") // doesn't work
      },

      hide: { when: 'mouseout', fixed: true },

       position: {
         corner: {
            target: 'bottomRight',
            tooltip: 'topLeft'
         }
      }
   });

});

my html code is as follows:

<div>this is the text and I would like to reference the <a href="product.php" class="tippy" id="123456">superproduct</a> with qtip.</div>

I'm pretty stuck, could you give me a hand, please?

+3
source share
1 answer

Use each():

$('.tippy').each(function() {  
   $(this).qtip({
          content: {
              url: "http://mydomain.com/product/mini/" + $(this).attr("id")
          },
          hide: { when: 'mouseout', fixed: true },   
          position: {
             corner: {
                target: 'bottomRight',
                tooltip: 'topLeft'
             }
          }
   });
)};

, $(this) , : ( , , this .tippy). $(this).attr() , qtip(). , , $('.tippy'), this, , window.

+4

Source: https://habr.com/ru/post/1754974/


All Articles