Setting id and adding CSS class to Poshy Tip toolt

2019-09-01 15:16发布

问题:

How do I set the id or add an extra CSS class to a tooltip div created with Poshy Tip? I'd like to be able to distinguish between different tooltips that are displayed at the same time.

I've tried adding the extra CSS class in the initialization of the tooltip, but this breaks the layout as there is some CSS generated on the fly by Poshy Tip that stops functioning correctly. The plugin provides no option to set the id:

$('#tip').poshytip({
    className: 'tip-yellow',
    // Replacing the previous line with the next one breaks the layout:
    // className: 'tip-yellow extraClass',
    // This option doesn't exist:
    // id: 'myId',
    ...
}

See this fiddle.

Can we add extraClass and set myId after initialization?

My jQuery skills are limited, so chances are I'm simply overlooking something.

回答1:

I couldn't get the text-decoration to work but I did change the color:

I commented out classname: 'tip-yellow'

and added this at the bottom:

$('.tip-yellow:last').addClass('extraClass');

Your Fiddle v2

UPDATE: add ID to it as well

Your Fiddle v3