and JS: form.on('mouseover', '.pin', function(e) { var id = this.id" /> and JS: form.on('mouseover', '.pin', function(e) { var id = this.id" /> and JS: form.on('mouseover', '.pin', function(e) { var id = this.id"/>

jQuery how to get paragraph's width in px?

61 views Asked by At

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?

1

There are 1 answers

2
Dimitris Siakavelis On

Try with jQuery width. Example:

var foo = $(".hidden").width();
alert(foo);