我打破了我的頭如何獲得一個特定的childs div id的風格是塊; 我一直在谷歌搜索和stackoverflow瀏覽孔日。得到一個樣式=區塊的div id
我能夠通過讓所有的孩子:
var active = $('#myDiv').children().get();
但我不知道如何爲風格進行篩選。 .get()在.get()之後不被允許。 所以,我只想知道id,因爲我需要使用它後。
編輯:
下面是完整的功能,我想用:
// ON MODAL DISMISS, RESET STEPS
$('#myDiv').on('hidden', function() {
var currentStep = $('#myDiv').children().filter(function(){
return $(this).css('display') === 'block';
});
//console.log(currentStep);
replace(currentStep, step1);
});
function replace(hide, show) {
document.getElementById(hide).style.display="none";
document.getElementById(show).style.display="block";
}
HTML:
<div id="myDiv">
<div id="step1">
...
</div>
<div id="step2">
...
</div>
<div id="step3">
...
</div>
</div>
目前,當我啓動模式,並通過步走,但決定在步驟3消除模態並重新啓動模態它將在步驟3繼續。因此,我認爲在解僱前我需要當前步驟,所以我可以將它發送給我的替換函數,並將currentStep的樣式設置爲none,並將第一步設置爲阻止。
你能否包含一些html?那麼舉個例子比較容易。我有一種感覺,你可能在尋找的是http://api.jquery.com/find/。我會給所有的孩子上課,而不是特定的風格。然後用Jquery find來找到那個班的孩子。我知道這不同於風格選擇。但我相信這會是一個更好的方法。我沒有發佈這個答案,因爲它是更多的選擇。 –
您將無法獲得特定的childs div id,只有具有'display:block'的所有孩子。 – migg
這只是一個預感,但也許你可以使用這樣的事情:** http://jsfiddle.net/sp2nK/** - http://api.jquery.com/visible-selector/ - http:/ /api.jquery.com/not-selector/ – Joonas