0

I have the following;

<div class="pin">
<p class="pin-text hidden">text</p>
</div>

and JS:

form.on('mouseover', '.pin', function(e) {
    var id = this.id;
    if($('#' + id).children('p.pin-text').length) {
        pin_text_width = ($('#' + id).children('p.pin-text').parent().width()).toString() + 'px';
        pin_text = $('#' + id).children('p.pin-text').text();
    }
});

I need to find the paragraph's text width in order to size a PNotify tooltip with variable width:

tooltip = new PNotify({
    text: pin_text,
    width: pin_text_width,
    ....

How can I calculate the text (words) width?

4

1 回答 1

0

尝试使用jQuery 宽度。例子:

var foo = $(".hidden").width();
alert(foo);
于 2018-06-18T13:26:48.507 回答