2014-07-04 14 views
0

的HTML屬性目前我有這樣的:入門用戶腳本和尋找一個JavaScript API來的JavaDoc相似,隨着獲取的變量

enter (function move() { 
// ==UserScript== 
// @name   DriversEd Time Saver! 
// @namespace  [email protected] 
// @description Automatically goes to the next slide once the timer is done. 
// @copyright  2014+, Marque Kuem 
// @license  GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html 
// @license  (CC); http://creativecommons.org/licenses/by-nc-sa/3.0/ 
// @version  0.1 
// @icon   https://driversed.com/img/logo.png 

// @homepageURL https://duckduckgo.com/ 
// @supportURL https://duckduckgo.com/ 

// @include  https://driversed.com/dashboard/course/* 

// ==/UserScript== 
    var timer=document.getElementById("timerValue"); 
    if(timer instanceof timer hide) { 
     alert('Next is clickable'); 
    } 
    setTimeout(move, 500); 
})(); 

我試圖查詢每半秒如果在變量id timerValue的頁面具有屬性timer和hide。這是HTML線的時候,我應該得到一個警告:

<div id="timerValue" class="timer hide">00:01</div> 

這是該行中,我不應該:

<div id="timerValue" class="timer">99:99</div> 

我怎麼會去檢查,如果計時器的HTML屬性計時器並隱藏「另外,是否有像Java API一樣的Javascript文檔?

+0

Javascript類與HTML類無關。 'instanceof'用於Javascript類。 – Barmar

+0

類名中沒有空格,類屬性是空格分隔的列表。 – Barmar

+0

謝謝你的澄清! – pandather

回答

0

使用querySelector來查找元素,如果它匹配所有你想要的標準如果它沒有類,選擇器將不會匹配任何東西。

setInterval(function() { 
    var timer = document.querySelector("#timerValue.timer.hide"); 
    if (timer) { 
     alert('Next is clickable'); 
    } 
}, 500); 
+0

謝謝!非常感謝。 :) – pandather

相關問題