user474901
user474901

Reputation:

get the size of label text inside the div?

I am trying to get the size of label text inside the div and chech of the size is 0 hide this div

Update the text is in dnn_ctr2802_View_lblHelp class dnnHelpText

javascript

  $('.dnnTooltip').dnnTooltip();
    //get the size of the hiden label
    var labelTextSize = $(".dnnHelpText").val().length;
    console.log("labelTextSize");

    if(labelTextSize == 0)
    {
        $('.dnnTooltip').hide()
    }

html

 <div class="pull-right eyeball">
    <img id="img_type" src="/ideaPark/DesktopModules/ExplorationTypeSaftyAlert/img/3.png" />
    <img id="img_safety_alert" class="eyeball-warning" src="/ideaPark/DesktopModules/ExplorationTypeSaftyAlert/img/exploration-warning.png" />
</div>

<div class="dnnTooltip">
<label id="dnn_ctr2802_View_label">
    <a id="dnn_ctr2802_View_cmdHelp" tabindex="-1" href="javascript:__doPostBack(&#39;dnn$ctr2802$View$cmdHelp&#39;,&#39;&#39;)"><span id="lblLabel"></span></a>

</label>
<div id="dnn_ctr2802_View_pnlHelp" class="dnnFormHelpContent dnnClear" style="display:none;">

    <span id="dnn_ctr2802_View_lblHelp" class="dnnHelpText"> bnmbnmbnmbnmtfgjnfvyg</span>
    <a href="#" class="pinHelp"></a>

</div>

Upvotes: 0

Views: 3156

Answers (2)

user474901
user474901

Reputation:

try this & BTW try to use jquery UI function .remove()

   var labelTextSize = $('.dnnHelpText').text().length;
    console.log("text:" + labelTextSize.length);
    if (labelTextSize == 1) {
        $('.dnnTooltip').remove();
    }

Upvotes: 1

DontVoteMeDown
DontVoteMeDown

Reputation: 21475

Try this:

var labelTextSize = $("#lblLabel").width();

And to test, try this:

console.log(labelTextSize);

UPDATE:

As anything worked I have search for other way to achieve this. I have found this question and maybe it works for you.

Try this:

$(".dnnHelpText").bind("DOMSubtreeModified", function(){
    var labelTextSize = $(this).width();

    if(labelTextSize == 0)
    {
        $('.dnnTooltip').hide()
    }
});

That snipet add an event listener when the content of the label is been changed. So then, inside the event you may have access to it's properties to do your routine.

Upvotes: 0

Related Questions