2011-10-19 18 views
0

jqueryは順序付きリストの高さを処理しますか?私はNULLを返すようになっています。順序付き/順序なしリストの高さが返されない

JS

var highestCol = $('ol.mostrecent').height(); 
    console.log(highestCol); 

HTML

<ol class="mostpopular"> 
    <li class="heading"><span class="item"></span><span class='desc'>Most Popular Topics</span></li> 
    <li class="first rank1 alt1"><span class='desc'><a href='/link/portal/8202/8390/Article/46/How-do-I-view-my-To-Do-List-items' class=contentLinks >How do I view my To Do List (items)?</a></span></li> 
    <li class="rank2 alt2"><span class='desc'><a href='/link/portal/8202/8390/Article/99/Do-I-have-to-complete-a-FAFSA-each-year' class=contentLinks >Do I have to complete a FAFSA each year?</a></span></li> 
    <li class="rank3 alt1"><span class='desc'><a href='/link/portal/8202/8390/Article/55/Find-or-Reset-Your-Password' class=contentLinks >Find or Reset Your Password </a></span></li> 
    <li class="rank4 alt2"><span class='desc'><a href='/link/portal/8202/8390/Article/219/Can-I-appeal-my-Financial-Aid-Denied-status-What-is-the-process' class=contentLinks >Can I appeal my Financial Aid Denied status? What is the process?</a></span></li> 
    <li class="rank5 alt1"><span class='desc'><a href='/link/portal/8202/8390/Article/104/Grants-Available-at-NOVA' class=contentLinks >Grants Available at NOVA!</a></span></li> 
    </ol> 
    <ol class="mostrecent"> 
    <li class="heading"><span class="desc">Most Recent Topics</span></li> 
    <li class="first alt1"><span class='item'>9/15/2011</span><span class='desc'><a href="/link/portal/8202/8390/Article/232/What-does-NOVA-consider-a-full-time-or-a-part-time-student" class=contentLinks >What does NOVA consider a full-time or a part-time student?</a></span></li> 
    <li class="alt2"><span class='item'>9/15/2011</span><span class='desc'><a href="/link/portal/8202/8390/Article/228/Information-regarding-Veterans-Benefits" class=contentLinks >Information regarding Veterans Benefits</a></span></li> 
    <li class="alt1"><span class='item'>9/15/2011</span><span class='desc'><a href="/link/portal/8202/8390/Article/227/What-is-the-status-of-my-special-circumstances-request-My-financial-situation-has-not-changed" class=contentLinks >What is the status of my special circumstances request? My financial situation has not changed.</a></span></li> 
    <li class="alt2"><span class='item'>9/15/2011</span><span class='desc'><a href="/link/portal/8202/8390/Article/226/The-income-used-on-my-FAFSA-has-greatly-changed-from-that-tax-year-to-this-Is-there-anything-I-can-do" class=contentLinks >The income used on my FAFSA has greatly changed from that tax year to this. Is there anything I can do?</a></span></li> 
    <li class="alt1"><span class='item'>9/15/2011</span><span class='desc'><a href="/link/portal/8202/8390/Article/225/If-I-receive-a-scholarship-s-can-I-still-get-financial-aid-funding" class=contentLinks >If I receive a scholarship(s) can I still get financial aid funding?</a></span></li> 
    </ol> 
+1

セレクタで何かを選択してもよろしいですか? – Samich

+0

あなたのHTMLも共有していますか? –

+0

'mostrecent'というクラスのリストを選択していますが、' mostpopular'クラスのリストは選択しています。 –

答えて

0

、そのページ上のコードは次のようになります。

jQuery(document).ready(function ($) { 
    if (!$.trim($('h1').html()).length) { 
     $('h1').hide(); 
    }; 
}); 

var highestCol = $("ol.mostrecent").height(); 
console.log(highestCol) 
console.log("here"); 

(document).readyブロックの外側の高さを測定しているのコード - あなたDOMがレンダリングされる前に高さを計算しようとしています。これは正常に動作するはずです:

jQuery(document).ready(function ($) { 
    if (!$.trim($('h1').html()).length) { 
     $('h1').hide(); 
    }; 

    var highestCol = $("ol.mostrecent").height(); 
    console.log(highestCol) 
    console.log("here"); 
}); 
+0

ありがとうございます。私は愚かだと感じる。 – runners3431

+0

理由はありません。私たち全員が、私たちが認めているよりも頻繁に起こります。 – Blazemonger

関連する問題