2012-01-28 73 views
0

編輯:新增UL類如何添加類H4標籤,它是在第二李 - jQuery的

<ul class="expand-coll-list"> 
    <li> 
    <h4 class="title-exp-coll title-expand"> 
    <span class="exp-coll"></span>Bookmarks</h4> 
    <div class="item-list"> 
    <ul>  
    <li class="first"><div>first Asset</div></li> 
    <li><div>Latest Updates</div></li> 
    <li><div>asset image</div></li> 
    <li><div>test Asset 1</div></li> 
    </ul></div> 
    </li> 

    <li> 
    <h4 class="title-exp-coll title-expand"> 
    <span class="exp-coll"></span>Menu</h4> 
    <p>No menu.</p> 
    </li> 
    </ul> 

例如,如果我加載內容/第1頁

我需要刪除類TITL -expand並在H4標籤這是第一李加級冠軍崩潰

例如,如果我加載內容/第2頁

我需要做同樣的功能在H4標籤,它是在第二李第1頁

我的代碼:

這對於第一種情況下工作,但不爲第二...

if(arg[1] == 'content' && arg[2] == 'page1') { 
    $(".expand-coll-list li:first").children("h4").removeClass("title-collapse").addClass("title-expand"); 
} else if(arg[1] == 'content' && arg[2] == 'page2') { 
    $(".expand-coll-list li:eq(1)").children("h4").removeClass("title-collapse").addClass("title-expand"); 
} 

它有什麼問題嗎?

在此先感謝..

+0

我沒有看到你把.expand-coll-list放在你html的任何地方?是你所有的HTML? – 2012-01-28 07:14:06

+0

@@ Benny:請看現在。添加ul類 – Fero 2012-01-28 07:30:06

回答

1

嘗試使用css3選擇器:nth-​​child(),應該幫助你解決問題! $('。expand-coll-list li:nth-​​child(indexOfLiGoesHere)')。addClass('classToBeAdded');

+0

爲css3選擇器+1:nth-​​child()..謝謝...它現在可以工作.. – Fero 2012-01-28 07:34:03

0

你的代碼試圖刪除不目前在H4的(標題崩潰)存在的類,並添加他們已經有了一個類(標題展開)。甚至沒有檢查你的選擇器是否正確,它不會出現這個代碼會做任何事情。

相關問題