2012-08-12 83 views
0

如何正確編輯下面的行以包含特定的類,而不是href屬性?定義一個類而不是屬性

var activeTab = $(this).find("a").attr("href"); 
+2

準確地說,「包含一個特定的類」是什麼意思?請添加更多細節或理想情況下的示例。 – 2012-08-12 14:53:41

+0

你想要選擇什麼課程? – 2012-08-12 14:53:45

回答

1

嘗試

var activeTab = $(this).find("a.className").attr("href"); 

如果使用

.attr("href"); 

它不會匹配href而是會返回匹配a標籤

1

嘗試的href;

var activeTab = $(this).find('.your_class').attr("href"); 

或者您可以嘗試closest() like;

var activeTab = $(this).closest('tr').find('.your_class').attr("href"); 
//i took <tr> as a child in this example just for a demo. You may change it according to your HTML structure 

或者您可以嘗試children like;

var activeTab = $(this).children('.your_class').attr("href"); 

希望這會有所幫助。

相關問題