Bibash Adhikari
Bibash Adhikari

Reputation: 292

Why does jQuery return null for element height?

I faced the same problem as that is mentioned by Matt but it is little different. I am trying to get height of a div but every time I get null.

HTML:

<div id="main" class="box-main " style="display:block">
    <div class="box_content" style="position:absolute;top:0px;bottom:0px;height:453px;width:100%;padding-left:5px;padding-bottom:2px;">
        <div style="min-width:200px;min-height:41px;padding-top:8px" id="ass-1415241823647 item-97"><div class="box">
           <div class="new-try item_message" title="ram"><div class="pp"><img src="images/try.jpg" class="avatar " width="40" height="40"></div>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
           </div>
        </div>
    </div>
</div>

JavaScript:

$(document).ready(function(){
   alert($("#ass-1415241823647 .item_message").height());
});

I tried this too but it didn't work.

$(document).ready(function(){
   alert($("#main .box_content #ass-1415241823647 .box .item_message").height());
});

Upvotes: 1

Views: 3226

Answers (4)

Suraj Rawat
Suraj Rawat

Reputation: 3763

ass-1415241823647 item-97 you can't have two id's remove one or try using class if u really want to

Upvotes: 4

Syed Muhammad Zeeshan
Syed Muhammad Zeeshan

Reputation: 1045

Try this using jquery:

$(document).ready(function(){
   alert($(".item_message").css("height"));
});

Hope this helps.

Upvotes: 0

sujin
sujin

Reputation: 34

Isn't the result of $("#ass-1415241823647 .item_message") empty jQueryObject? length 0?

.. id="ass-1415241823647 item-97">.. 

value of id attributes was wrong.

Upvotes: 0

TGH
TGH

Reputation: 39248

You don't seem to have any elements in your markup matching the selector #ass-1415241823647 .item_message" so it's unable to locate it.

Upvotes: 0

Related Questions