如何在突变中选择相同的类名

时间:2019-05-27 20:06:44

标签: javascript

我想选择所有“ chat_cont”类。但其中有太多。而且他们没有任何父母。但是,另一个类(“ chat_cont”的父级)有一个父级。但是我想选择“ chat_cont”。我该怎么办?

我试图用此代码选择所有类,但没有用;

var target = { function hide_download_btns(){
if (document.getElementById('download_btn_var_input').value == "true") {
    document.getElementsByClassName('project_download_btn').item(0).hidden = true
    }
}; };
    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;


    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {


            var b = mutation.addedNodes;
            b.forEach(function(element) { var mesaj = element.querySelector('.msg-body').innerText; var isim = element.querySelector('.user-name').innerText.replace(":",""); if(isim.includes("Badman")) { if(mesaj.includes("under me")) { document.getElementsByClassName("chat-input")[0].value = "dabc"; document.getElementsByClassName("chatInputSend")[0].click(); } }  


            });

        });
    });


    var config = {
        attributes: true,
        childList: true,
        characterData: true
    };


    observer.observe(target, config);

我已经尝试过,错误是=“无法在'MutationObserver'上执行'observe':参数1的类型不是'Node'。” ;

var target = document.getElementsByClassName("chat_cont");
    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;


    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {


            var b = mutation.addedNodes;
            b.forEach(function(element) { var mesaj = element.querySelector('.msg-body').innerText; var isim = element.querySelector('.user-name').innerText.replace(":",""); if(isim.includes("Badman")) { if(mesaj.includes("under me")) { document.getElementsByClassName("chat-input")[0].value = "dabc"; document.getElementsByClassName("chatInputSend")[0].click(); } }  


            });

        });
    });


    var config = {
        attributes: true,
        childList: true,
        characterData: true
    };


    observer.observe(target, config);

这里,每个chat_cont都有的所有代码;

<li class="chat_msg msg-user-message read"><div class="colorbar user"></div><span class="user chat_user"><span class="chat_user_prof"><img src="https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/40/40080c1d9f36eeaaf6793d9535288036d9468a36.jpg"></span><span class="xp_50"><i class="icon"></i><span class="level_val">53</span></span><a class="chat_user_name">Triva Hunter Ghetto | <span class="icon-balanceicon namepromotion" title="This user has activated the Name Promotion"></span></a><span class="chat_user_ico"><i class="icon-gammdom-symbol"></i><span class="chat_user_colen">:</span></span></span><span class="chat_cont">bendede oluyodu</span></li>

他们有一个名为“ messages”的父母; (“ chat_msg msg-user-message read”具有该父对象)

0 个答案:

没有答案